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.
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |