Drop Failed for User - Error MSSQLSERVER 15421

In a SQL Server 2005 database, I was having a hard time deleting a 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:

Msdn No Results Msg 15421

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 the 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 specifiy the user name and not the login name. 'DeleteMe' is the user name I want to delete. See the screen shot below:

Database User Dialog

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

Results

With that knowledge, I opened the role dialog in SQL Server Management Studio and changed the owner to 'dbo'. Below is the before screen shot.

Database Role Properties Dialog - Before

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

new owner

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值