Click here to Skip to main content
13,140,023 members (49,268 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 19 Mar 2010

Few Step(s) to Remove SQL Server Database User(s)

, 20 Mar 2010
Rate this:
Please Sign up or sign in to vote.
Few step(s) to remove SQL Server database user(s) when you are facing error like “The database principal owns a database role and cannot be dropped.” for dropping a user.


Database security is one of the significant concerns for most DBAs. DBAs frequently restore or backup the database, this is a very common scenario, But the thing is after successfully restoring a new version of your database, you want to remove the current users. Probably you thought of just expanding the user node and deleting the desire user; in that sense you are somewhat correct. But if you face an error like:

Msg 15421, Level 16, State 1, Line 1
The database principal owns a database role and cannot be dropped.	 

What will you do?

Microsoft SQL Server provides quite a lot of ways to maintain the security of database. This article is not about the security of Microsoft SQL server.

In this article, I will try to explain how to resolve the following issues:

  1. The database principal owns a database role and cannot be dropped.
  2. The database principal owns a schema and cannot be dropped.


I try to categorize into two sections, section-A; we will discuss to find out the list of roles in which the user exists and the section-B; we will discuss how to resolve it.


In this section, our primary goal is to find out the list of existing roles of our target database. For this purpose, we use a simple transact-SQL with the help of SQL Server SYS.DATABASE_PRINCIPALS table. A sample SQL script and the required step(s) are listed below:

  1. Open SQL Server Management Studio and login as an admin user.
  2. Select the database, set the user name & execute the following transact-SQL for getting the database role and user detail.

Sample SQL Script

WHERE     (DBPRINCIPAL_1.NAME = 'User Name To Remove')  

The above transact-SQL returns a list of roles in which the user exists.

More information on "SYS.DATABASE_PRINCIPALS " table can be found at this link.


I think this is not a very intricate task, let’s start, your SQL Server Management Studio is open and you are logged in as an admin user i.e., “sa”.

From the section-A we already get the list, now the task is to remove the desired user. To do this, we need to follow the step(s) listed below:

  1. Now expand Databases node from object explorer.
    1. Select the target Database >>---> Security >>--> Roles >>--> Database Roles.
    2. Now double click the entries that were listed in the output of the above SQL command.
    3. Change the “Owner” to some temp username.
    4. If the username you want to delete appears in the dialog box, select and remove it from there too.
      (Do this for all the Roles that came up in the above SQL query.)
  2. Navigate to Databases >>--> the target Database >>--> Security >>--> Schemas.
    1. Double-click to open “db_owner” and change the schema owner to dbo.
  3. Now go to: Databases >>--> Target Database >>--> Security >>--> Users.
  4. Right click the username you want to delete and click “Delete”, then click OK in the new dialog box that appears.

Note: You can also try the stored procedure sp_dropuser after accomplishing the step(s) above except section-B step 4.


EXEC sp_dropuser 'User name' 


I hope this might be helpful to you. Enjoy!


  • MSDN


  • 20th March, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Md. Marufuzzaman
Bangladesh Bangladesh
A well experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by and also selected as a mentor of Published over 100 technical articles in various software development resource sites (i.e.,, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.

Over twelve years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.I have also more than two years’ of strong experience in mobile-VAS (platform development).

An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint.Honest, believes in transparency, commitment and teamwork.

Expertise: Software/Solution Architect, Research, MIS, Data Analytics, Data Mining, BI, SaaS platform base application development, Large scale Win32 Form/Web based business software solutions, Security, Enterprise applications development, integration, etc.

Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12/14 , Oracle version 10/11, MySql version 5.1, 5.5, 5.7, Visual C#, VB.NET, ASP.NET, API, MVC, WebAPI , WPF, WCF, PHP, Microsoft Power BI, SPSS, PS2, R, Add-In, Visual Basic etc.

.Net UI component: Telerik, DevExpress, Ext.Net.
Scripting language: JavaScript, AngularJS, node.JS.
Source control / Subversion: Git,SVN.
Development methodologies: Agile,RAD.
Project Management / Issues Tracking Tools: JIRA, ClockingIt.

You may also be interested in...


Comments and Discussions

QuestionMy vote of 4 Pin
LittleMatti25-Jun-13 1:02
memberLittleMatti25-Jun-13 1:02 
GeneralMy vote of 5 Pin
URVISH_SUTHAR113-Jun-13 3:22
memberURVISH_SUTHAR113-Jun-13 3:22 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman13-Jun-13 9:58
mentorMd. Marufuzzaman13-Jun-13 9:58 
GeneralSome alternative Pin
aldo hexosa13-Dec-10 17:14
memberaldo hexosa13-Dec-10 17:14 
GeneralRe: Some alternative Pin
Md. Marufuzzaman5-Oct-11 23:02
mvpMd. Marufuzzaman5-Oct-11 23:02 
GeneralMy vote of 1 Pin
Peter_Bernheim22-Mar-10 23:22
memberPeter_Bernheim22-Mar-10 23:22 
GeneralRe: My vote of 1 Pin
Md. Marufuzzaman22-Mar-10 23:54
mvpMd. Marufuzzaman22-Mar-10 23:54 
GeneralMy vote of 5 Pin
denic25-Mar-10 2:47
memberdenic25-Mar-10 2:47 
GeneralHi comanion Pin
Anil Srivastava21-Mar-10 21:15
memberAnil Srivastava21-Mar-10 21:15 
GeneralRe: Hi comanion Pin
Md. Marufuzzaman21-Mar-10 21:58
mvpMd. Marufuzzaman21-Mar-10 21:58 
GeneralGood work Pin
Mohd Arshad (Sam)19-Mar-10 10:28
memberMohd Arshad (Sam)19-Mar-10 10:28 
GeneralRe: Good work Pin
Md. Marufuzzaman19-Mar-10 16:45
mvpMd. Marufuzzaman19-Mar-10 16:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 21 Mar 2010
Article Copyright 2010 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid