Drop failed for user-error MSSQLServer 15421

Source: Internet
Author: User

In a SQL Server 2005 database, I was having a hard time deleting
User I had created.

I kept getting this error:

The Database Principal owns a database role and cannot be dropped.
MSG 15421.

Msdn and Google were not helpful on this error. ater lots of Search
Attempts I kept coming up empty:

I spent some time looking through various dialogs in SQL Server
Management studio. I was unable to find the problem-probably because I
Am not as familiar with the UI as I was with Enterprise Manager.

I finally wrote a script that helped me identify for which role
User was listed as an owner. Here it is:

Select dp2.name as role, dp1.name as owner
From SYS. database_principals as dp1 inner join SYS. database_principals
As dp2
On dp1.principal _ id = dp2.owning _ principal_id
Where dp1.name ='Deleteme
'

In the last line of the script, make sure you specifiyUser
Name

AndNot
The login name. 'delete' is the user
Name I want to delete. See the screen shot below:

After running this script, I found which role had my user listed
Owner.

With that knowledge, I opened the role dialog in SQL Server
Management studio and changed the owner to 'dbo'. below isBefore
Screen shot.

The owner shoshould be changed to a principal other than the one you are
Trying to delete. I used 'dbo' as shown here:

Once this change was made I was able to delete the user I wanted
Get rid.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.