Get the DB Owner through T-SQL

  • Hi All,

    Is it possible to get who is created a database through T-SQL?

    For Ex, if i see the Properties of a database there is a column called owner (who is created the database).

    Likewise, through T-SQL is it possible to achieve the same owner?

    Appreciate your help!!!

    ---

  • sqluser (6/3/2009)


    Hi All,

    Is it possible to get who is created a database through T-SQL?

    For Ex, if i see the Properties of a database there is a column called owner (who is created the database).

    Likewise, through T-SQL is it possible to achieve the same owner?

    Appreciate your help!!!

    ---

    You can get the owner of the database by running sp_helpdb. But the owner is not necessarily the user who created the database. In fact on most of the databases I work with, we change the owner to sa.

    [font="Verdana"]Markus Bohse[/font]

  • Thanks you very much MarkusB for your quick info. 🙂

  • MarkusB,

    Is it possible to achieve this through sql statement? Like sys.databases some thing like ....

    ---

  • sqluser (6/3/2009)


    MarkusB,

    Is it possible to achieve this through sql statement? Like sys.databases some thing like ....

    ---

    Is what possible?

    [font="Verdana"]Markus Bohse[/font]

  • This gives the owner of the database

    select suser_sname(sid),name from master..sysdatabases

    just add the relevant where clause for a particular database

    Retrieving who originally created the database (if different) I dont think can be done. If the owner has never been changed the above query will return the id the person who created the database was logged on with.

    ---------------------------------------------------------------------

  • george sibbald (6/3/2009)


    This gives the owner of the database

    select suser_sname(sid),name from master..sysdatabases

    just add the relevant where clause for a particular database

    Retrieving who originally created the database (if different) I dont think can be done. If the owner has never been changed the above query will return the id the person who created the database was logged on with.

    Thanks george... Very valuable information as per me.

    Thanks...

    ---

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

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply