Drop Failed for User – Error MSSQLSERVER 15421

來源:互聯網
上載者:User

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:

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:

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

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.

The owner should 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 to
get rid of.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.