SQL Server: Find Logins in SQL Server

SQL Server Logins

Question: Is there a query to run in SQL Server that will return all SQL Server Logins and information about those Logins?

Answer: In SQL Server, there is a catalog view (ie: system view) called sys.sql_logins. You can run a query against this system view that returns all of the Logins that have been created in SQL Server as well as information about these Logins.

To retrieve all Logins in SQL Server, you can execute the following SQL statement:

SELECT *
FROM master.sys.sql_logins;

The sys.sql_logins view contains the following columns:

ColumnExplanation
nameThis is the login_name that was assigned in CREATE LOGIN statement
principal_idNumeric value
sidThis is the sid that was assigned in CREATE LOGIN statement
typeType of principal
S = SQL Server user
U = Windows user
G = Windows group
A = Application role
R = Database role
C = Certificate mapped
K = Asymmetric key mapped
type_descDescription for type of principal
SQL_USER
WINDOWS_USER
WINDOWS_GROUP
APPLICATION_ROLE
DATABASE_ROLE
CERTIFICATE_MAPPED_USER
ASSYMETRIC_KEY_MAPPED_USER
is_disabled0 or 1
create_dateDate/time when Login was created using the CREATE LOGIN statement
modify_dateDate/time when Login was last modified using the ALTER LOGIN statement
default_database_nameThis is the default database assigned in CREATE LOGIN statement or ALTER LOGIN statement
default_language_nameThis is the default language assigned in CREATE LOGIN statement or ALTER LOGIN statement
credential_idThis is the credential assigned in CREATE LOGIN statement or ALTER LOGIN statement
is_policy_checked0 or 1, assigned by CREATE LOGIN statement or ALTER LOGIN statement
is_expiration_checked0 or 1, assigned by CREATE LOGIN statement or ALTER LOGIN statement
password_hashHashed value of the password

Older Version Compatibility

In older versions of SQL Server, you can retrieve all Logins using the SQL Server 2000 system tables such as the sys.syslogins table.

To retrieve all Users in SQL Server using the SQL Server 2000 system tables, you can execute the following SQL statement:

SELECT *
FROM master.sys.syslogins;

The sys.syslogins system table (SQL Server 2000) contains the following columns:

ColumnExplanation
sidThis is the sid that was assigned in CREATE LOGIN statement
statusNot applicable
createdateDate/time when Login was created using the CREATE LOGIN statement
updatedateDate/time when Login was last modified using the ALTER LOGIN statement
accdateNot applicable
totcpuNot applicable
totioNot applicable
spacelimitNot applicable
timelimitNot applicable
resultlimitNot applicable
nameThis is the login_name that was assigned in CREATE LOGIN statement
dbnameDefault database
passwordNULL
languageDefault language
denylogin0 or 1
hasaccess0 or 1
isntname0 or 1
isntgroup0 or 1
isntuser0 or 1
sysadmin0 or 1
securityadmin0 or 1
serveradmin0 or 1
setupadmin0 or 1
processadmin0 or 1
diskadmin0 or 1
dbcreator0 or 1
bulkadmin0 or 1
loginnameThis is the login_name that was assigned in CREATE LOGIN statement

Leave a Reply