Home > Functions and DMVs, SQL Queries, SQL Server, Stored Procedures, T-SQL > Get the owner of the database in SQL server

Get the owner of the database in SQL server

September 15, 2009 Leave a comment Go to comments

Sometimes it is important to get the owner of each database in a server. You can do this by checking the properties of the database. However checking the property of each and every database in a server can become a cumbersome job. Instead , you can use the function “SUSER_SNAME()” to get the name of any specific user. The parameter to this function is SID ( Security identification number ). The function prints the user name for a given SID.

Use the Query below to fetch the owner of the database

SELECT D.NAME [NAME],
SUSER_SNAME (OWNER_SID) [OWNER]
FROM SYS.DATABASES D

The output will look like

NAME OWNER
master sa
tempdb sa
model sa
msdb sa
ManagementDB_Archive tijo.p
ManagementDB_BeforeArchive tijo.p
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: