Monday, March 12, 2012

Find out owner of database for SQL 2000 and 2005 databases

Hello,
As the title says I need to find out the owner of database on both sql 2000 and 2005. I found a query which works great on sql 2005..

select suser_sname(owner_sid) from sys.databases where name = 'DatabaseName'

But cannot run this in QA against a sql 2000 database -- "Invalid object name 'sys.databases'."

Anyone know how I can accomplish this?

Select * from master.dbo.sysdatabases doesn't give me any promising data either,

BI was almost there...for anyone looking to do this you need to change a couple of clauses from the 2005 query i posted. Firstly SELECT *
FROM sys.databases -> SELECT * FROM master.dbo.sysdatabases and the column owner_sid needs to be changed to its 2000 equivalent of just sid...

All in all

2005: select suser_sname(owner_sid) from sys.databases where name = 'DatabaseName'

2000: select suser_sname(sid) from master.dbo.sysdatabases where name = 'DatabaseName'

B

No comments:

Post a Comment