List of all users in Azure SQL

白昼怎懂夜的黑 提交于 2021-01-27 17:50:32

问题


How can I list all users which can connect to my sql server database? Now able to find any sql command. I tried few links available on the internet but none of them worked.

Some commands that I tried

SELECT * FROM sys.sql_logins;

SELECT * FROM sys.sysusers;

select * from sys.sysusers
SELECT [name], [sid]
FROM [sys].[database_principals]
WHERE [type_desc] = 'SQL_USER'

I also looked in azure portal but did not find any users information.

I am able to connect to sql database which connection string where I am providing userid and password. Now I am not able to find that userid in sql server.

connection string looks like

value="Server=server,1433;Initial Catalog=DB1;Persist Security Info=False;User ID=user1;Password=pass1;Encrypt=True;Connection Timeout=30;" 

回答1:


Run this query on master:

SELECT A.name as userName, B.name as login, B.Type_desc, default_database_name, B.* 
FROM sys.sysusers A 
    FULL OUTER JOIN sys.sql_logins B 
       ON A.sid = B.sid 
WHERE islogin = 1 and A.sid is not null

Run this on user databases:

SELECT DB_NAME(DB_ID()) as DatabaseName, * FROM sys.sysusers


来源:https://stackoverflow.com/questions/46293095/list-of-all-users-in-azure-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!