Tuesday, February 1, 2011

'The database principal owns a schema in the database, and cannot be dropped' error in SQL Server 2005 & 2008

I ran into this situation today. I created a User, made him dbOwner to a database DBX. I no longer needed this User and so tried deleting and got this error.

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

After Googling for sometime, I found that this User called as "Database Principal" has "db_owner" role selected for the schema. This means the Database Principal I want to delete owns the schema.

One solution is to delete the schema and then delete the User. Another Solution was to change the DB_Owner to some another "Database Principal" - to "dbo". I did it and then I was able to delete the user/Database Pricipal successfully.

To change the DB_Owner to some another "Database Principal"; simply Drill Down to your Database in Sql Server Management Studio and further more Drill Down to your_DB_Name > Schemas > db_owner > right click > select properties. You would find the name of the "Database Principal" that you want to delete. Change this to some another "Database Principal"; for Example, to "dbo".

Reference here

No comments:

Post a Comment