Showing posts with label SID SQL Server restore database alter authorization SA. Show all posts
Showing posts with label SID SQL Server restore database alter authorization SA. Show all posts

Tuesday, March 29, 2011

The database owner SID recorded in the master database differs from the database owner SID recorded in database

The database owner SID recorded in the master database differs from the database owner SID recorded in database '<Database>'. You should correct this situation by resetting the owner of database '<Database>' using the ALTER AUTHORIZATION statement.

This problem can arise when a database restored from a backup and the SID of the database owner does not match the owners SID listed in the master database.

To correct this issue, run the following command:

Alter Authorization on Database::<Database> to [<USER>]

To check who is the owner listed in the master database run the following:

SELECT  SD.[SID]
       ,SL.Name as [LoginName]
  FROM  master..sysdatabases SD inner join master..syslogins SL
    on  SD.SID = SL.SID
 Where  SD.Name = '<Database>'

To check what SID is the DBO in the restored database run the following:

Select [SID]
  From <Database>.sys.database_principals
 Where Name = 'DBO'