SQL Code Snippets : Database Properties

List all the databases and their owners

select name as DatabaseName, suser_sname(owner_sid) as DBOwner
from sys.databases

Change database owner

sp_changedbowner ‘sa’

Get the compatibility level of a database

select compatibility_level
from sys.databases
where name = ‘DB_Name’

Get the database name

select db_name()

Advertisements