Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

Msg 15138 - The database principal owns a schema in the database and cannot be dropped.

13 January,2015 by Tom Collins

Question: I’ve attempted to drop a SQL Server database user. When I execute the  DROP USER , I receive the error message:

Msg 15138, Level 16, State 1, Line 2

The database principal owns a schema in the database, and cannot be dropped.

How can I fix this problem?

Answer:

Step 1 : Find out the database schemas owned by the database user

 

SELECT name FROM  sys.schemas WHERE principal_id = USER_ID(a_user_id)

 

Step 2 : Either drop the schema or change the schema owner

 

To drop the database schema

DROP SCHEMA [my_schema_name]

You may receive an error message  such as :

Cannot drop schema 'my_schema_name' because it is being referenced by object 'a_table'.

Investigate and decide on how you want to handle the objects within the schema. 

To change the schema owner

ALTER AUTHORIZATION ON SCHEMA::my_schema_name TO dbo

 

Step 3: Drop the SQL Server database user

DROP USER myUser


It's advisable to generate a backup or generate a script of the user status BEFORE you make any changes. 

Read more on managing SQL Server database security

 

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Msg 15138 - The database principal owns a schema in the database and cannot be dropped.


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer