Getting Server Name

  • Is there a function that will return the server name if you want to put the server name into a table and also a funtion that will return the login information?

    Edited by - qos on 08/04/2003 07:22:36 AM

  • select @@servername

    select select system_user

  • @@servername returns server name

    login information can be returned by the following. Note, each returns a slightly different piece of information. Each one is useful depending on what you are looking for from the login.

    1. SUSER_SNAME to get the SQL Server login name or Windows account associated with a security_identifier. This requires a server_user_id and will use that to return the associatedc name from the sysusers table. If no server_user_id is supplied then the current is returned.

    2. SUSER_SID to get the security_identifier associated with a SQL Server login name or Windows NT account. Returns the server_user_id for the supplied login name. If no login name is supplied then the current user info is returned.

    3. USER_ID to get the database user ID associated with the current connection. Returns a database identification for a user name. If no name is supplied the current user information is returned

    4. USER_NAME to get the database user name associated with a database user ID. returns a user name from a given user id number. If no user id number is supplied then the current user information is returned

    5. SESSION_USER. This returns the session user name. If a user is a member of the dbo role then the returned value would be 'dbo' not the username.

    6. SYSTEM_USER. This returns the system user name. if a user is a member of the dbo role this would still return the user name not the role name.

    Hope this helps,

    Scott B Dragoo

    GIS Systems Analyst

    Sangamon County, Illinois

    scottd@co.sangamon.il.us

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply