List_Azure_SQL_Logins

Snippet Name: List_Azure_SQL_Logins

Tags:

Created Date: 2025-06-16 13:12:44
Last Modified Date: 2025-05-31 10:31:39

Dependencies:

DBA Notes:

Sample Output:

Title: List Azure SQL Logins
Author: user
in an azure SQL server, i have two database instances. how can i list the logins i have already created

Author: ChatGPT
To list the logins that have already been created in an Azure SQL Database, you can query the `sys.sql_logins` system view. This view contains information about the SQL logins that have been created.

Here's the query to list the logins:

```sql
SELECT name, create_date, modify_date, type_desc, is_disabled 
FROM sys.sql_logins;
```

This will return a list of logins along with their creation and modification dates, type, and whether they are disabled or not.

If you are using a SQL Server on an Azure Virtual Machine (VM) or an Azure SQL Managed Instance, you can use a similar query. However, for Azure SQL Database, remember that the `sys.sql_logins` view might not be available. Instead, you can use the following query to list the users (which are linked to logins in a traditional SQL Server):

```sql
SELECT name, type_desc, create_date, modify_date 
FROM sys.database_principals
WHERE type IN ('S', 'E', 'X');
```

This will give you a list of users of type SQL user (`S`), external user (`E`), and external group (`X`).

Additionally, for Azure SQL Database, you can use the `sys.database_principals` view to check the database-specific principals:

```sql
SELECT name, type_desc, create_date, modify_date 
FROM sys.database_principals
WHERE type IN ('S', 'E', 'X');
```

This query will provide you with the names, types, and creation/modification dates of the database principals, which include the logins.

Make sure to execute these queries on the relevant database context where you want to list the logins or users.


Leave a Reply