SQL Msg 15138: The database principal owns a schema in the database, and cannot be dropped.

Here’s my script to fix this error. This occurs when I restore a database to another server and want to remove the source server users.


DECLARE @vcSchemaName VARCHAR(128);
SET @vcSchemaName = 'schema name goes here'
SELECT s.name,
 'ALTER AUTHORIZATION ON SCHEMA::[' + @vcSchemaName + '] TO dbo;'
FROM sys.schemas s
WHERE s.principal_id = USER_ID(@vcSchemaName

Comments are closed.

Post Navigation