Categories:

Need to change database owner programmatically?

-- check the owner of the database
select suser_sname(owner_sid) from sys.databases where name = 'db_name'

-- change DB owner
EXEC sp_changedbowner 'sa'

-- if the first doesn't work
EXEC dbo.sp_changedbowner @loginame = 'sa', @map = false

Tags:

Comments are closed