How to get the list of all database users

前端 未结 6 1947
感情败类
感情败类 2021-01-30 06:40

I am going to get the list of all users, including Windows users and \'sa\', who have access to a particular database in MS SQL Server. Basically, I would like the list to look

6条回答
  •  独厮守ぢ
    2021-01-30 06:52

    For the SQL Server Owner, you should be able to use:

    select suser_sname(owner_sid) as 'Owner', state_desc, *
    from sys.databases
    

    For a list of SQL Users:

    select * from master.sys.server_principals
    

    Ref. SQL Server Tip: How to find the owner of a database through T-SQL

    How do you test for the existence of a user in SQL Server?

提交回复
热议问题