none
How to get the database owner name in T-SQL script

    질문

  • Hello, All!

    I want to get the database ower name (in format DOMAIN\user) by through T-SQL script. But SELECT * FROM sys.databases returns only owner_sid.

    Please show me a way - how to get the owner name, if you have only owner_sid. Or, may be, somebody know another way ?


    Andy Mishechkin

    2012년 10월 17일 수요일 오전 6:38

답변

모든 응답

  • SELECT suser_sname( owner_sid ), * FROM sys.databases


    http://www.t-sql.ru

    • 답변으로 표시됨 Andy Mishechkin 2012년 10월 17일 수요일 오전 8:17
    2012년 10월 17일 수요일 오전 6:42
  • Try

    select suser_sname(owner_sid) from sys.databases;


    Many Thanks & Best Regards, Hua Min


    • 편집됨 HuaMin Chen 2012년 10월 17일 수요일 오전 7:01
    2012년 10월 17일 수요일 오전 7:01
  • Thanks
    2014년 11월 21일 금요일 오전 11:57
  • I know this is an old string, but someone (like me) might need to know a few more details on how to do this.

    If you want to get the owner / creator of all databases on your server;

    select name AS 'Database'

           , suser_sname(owner_sid) AS 'Creator'

     from sys.databases;

     GO

    If you want to get the owner / creator of a specific database;

    select name AS 'Database'

           , suser_sname(owner_sid) AS 'Creator'

     from sys.databases

    WHERE name = 'AdventureWorks';

    GO

    While the other answers on this page do return the creator of all the databases on your system, the commands do not tell you which database this person created. In my code above; the “name” calls the database name in one column and the “Creator” list the creators of the databases respectively in another column.

    Hope this helps someone in the future.

    2018년 7월 13일 금요일 오후 5:53