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

Insus.NET發表於2021-08-29

 

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

主資料庫中記錄的資料庫所有者SID與資料庫'DB_NAME'中記錄的資料庫所有者SID不同。 您應該透過使用ALTER AUTHORIZATION語句重新設定資料庫“DB_NAME”的所有者來糾正這種情況。 

解決辦法:

 

The database owner SID recorded in the master database differs from the database owner SID recorded in database 'DB_NAME'
DECLARE @Command VARCHAR(MAX) = 'ALTER AUTHORIZATION ON DATABASE::<<DatabaseName>> TO [<<LoginName>>]' 

SELECT @Command = REPLACE(REPLACE(@Command 
            , '<<DatabaseName>>', DB_NAME())
            , '<<LoginName>>', sp.name)
FROM sys.databases db JOIN
        sys.server_principals sp ON sp.sid = db.owner_sid
WHERE db.name = 'master'

EXEC(@Command)
GO
Source Code

 

相關文章