Unable to drop database role in SQL Server

I just ran into an issue where I was unable to delete a database role, somehow my custom database role had become the owner of the db_datareader role.

Deletion of the role was not possible due to the following error:

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

The solution is straightforward:

First find out which schema is being owned by the rolename:

SELECT name FROM sys.schemas WHERE principal_id = USER_ID( ‘<rolename here>‘ )

Then change ownership using:

ALTER AUTHORIZATION ON SCHEMA::<schemaname here> TO dbo

After which you can drop the role

DROP ROLE <rolename here>

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s