Ms Sql 2008 Error 15138
Contents |
| Related Tips: More > Security Problem Recently I had an issue while dropping an orphaned user for an obsolete login. I microsoft sql server error 15138 was unable to drop the user and it failed with the below error remove user from schema sql server messages. Msg 15421, Level 16, State 1, Line 1 The database principal owns a database role and cannot be
The Database Principal Owns A Database Role And Cannot Be Dropped
dropped. Msg 15138, Level 16, State 1, Line 1 The database principal owns a schema in the database, and cannot be dropped. Solution In this article I will explain what needs to
The Database Principal Owns A Service In The Database And Cannot Be Dropped
be done prior to dropping the user if it failed with error message 15421 or error message 15138. As per Microsoft SQL Security you cannot drop a user in one of the below scenarios: Database Principal/User owns a database role Database Principal/User owns a schema To learn more about orphaned users take a look at this tip Understanding and dealing with orphaned users in a sql server drop schema SQL Server database. Query to Get Database Roles Owned by a User You can run this script to get a list of database roles owned by a particular user. Just substitute the orphaned user name where I have "Jugal". -- Query to get the user associated Database Role select DBPrincipal_2.name as role, DBPrincipal_1.name as owner from sys.database_principals as DBPrincipal_1 inner join sys.database_principals as DBPrincipal_2 on DBPrincipal_1.principal_id = DBPrincipal_2.owning_principal_id where DBPrincipal_1.name = 'Jugal' Query to Get Database Schemas Owned by a User You can run this script to get a list of schemas owned by a particular user. Just substitute the orphaned user name where I have "Dj". -- Query to get the user associated schema select * from information_schema.schemata where schema_owner = 'Dj' As a next step to fix the issue we will transfer the ownership of the database role or schema to DBO. We can do this using either SSMS or a T-SQL script. Fix Error Msg 15421 Using SSMS to Fix the Error Go to Object Explorer > Connect to the Target Server > Expand the target Database > Expand Security > Expand Roles > Expand Database Roles-> Righ
in SQL Server OUTPUT Clause in SQL Server SQL Server Configuration Manager not found in Programs list Set First Day of the Week in SQL Server Built-in Logical Function CHOOSE in SQL Server How to Script SQL Server Configuration Options How to
Cannot Drop Schema Because It Is Being Referenced
List all Disabled Indexes in a SQL Server Database How to Disable and Enable Index the database principal owns a fulltext catalog in the database and cannot be dropped in SQL Server SQL Server Buffer Pool Memory used by each Object and each Database SQL Server Views WITH CHECK OPTION See the alter authorization on schema Default Schema of SQL Server Database Users and Groups How to List all SQL Logins with Passwords not Enforced by Policies How to List all Locked SQL Logins in SQL Server EOMONTH Function to Get First and Last Day https://www.mssqltips.com/sqlservertip/2620/steps-to-drop-an-orphan-sql-server-user-when-it-owns-a-schema-or-role/ of a Month in SQL Server Concatenate SQL Server Columns that contain NULL values How to convert VARCHAR to Integer in SQL Server with CAST and CONVERT « « » » How to enable and disable trace flags, or check for active trace flags in SQL Server How to drop database user that owns a schema - SQL Server Error: 15138 When you try to remove the user from database which owns a schema in the http://zarez.net/?p=179 database you will get the following error: The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138) and you will not be able to remove the user until you change the schema owner. To change the schema owner from Sql Server Management Studio: Expand your database -> Security -> Schemas. In the Object Explorer Details you can see a list of the schemas and the owners: Right click on the schema that is owned by the user you want to delete and change the owner (Properties -> General -> Schema Owner). Query: Run the following query if the user you are trying to drop is named for example ‘my_app_user’ and it exists in the database ‘AW2008’: USE AW2008;
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('my_app_user'); Here is my result: And change the owner of the schema to some other user (for example dbo): ALTER AUTHORIZATION ON SCHEMA::db_datawriter TO dbo; When the user you want to delete has no schemas owned you can delete it. If the post helped you, please share it: May 25th, 2012 | Tags: SQL Server | Category: SQL Server 9 comments to How to drop database user that owns a schema - SQL Server Error: 15138 burana March 15, 2014 at 1:54 am · Reply it work! Many Thanks, IrrerIvan May
cannot be dropped!! 05 Wednesday Feb 2014 Posted by Subhro Saha in SQL Server: Administration ≈ 1 Comment TagsAlter Authorization, Database Principal, Drop User, Schema, SQL Error https://subhrosaha.wordpress.com/2014/02/05/sql-server-error-15138-the-database-principal-owns-a-schema-in-the-database-and-schema-cannot-be-dropped/ 15138, sys.schemas Today one of my reader asked a question about http://dba.stackexchange.com/questions/19456/the-database-principal-owns-a-schema-in-the-database-and-cannot-be-dropped-mess how to fix the error while trying to remove a login from a database. The reader was getting the below error: Msg 15138, Level 16, State 1, Line 1The database principal owns a schema in the database, and cannot be dropped. The error message of SQL sql server Server is self explanatory as there were schema associated with the user and we have to transfer those schema before removing the User. In this post I will explain the workaround for this error: Lets assume I am trying to drop a user named "TestUser" from DemoDB database. Now, run the below query in the database from which the database principal we are trying to drop the user. Use DemoDB ;SELECT s.nameFROM sys.schemas sWHERE s.principal_id = USER_ID(‘TestUser') In my test scenario, I got the below result set from the above query: Then, use the names found from the above query below in place of the SchemaName below. And drop your user. ALTER AUTHORIZATION ON SCHEMA::SchemaName TO dbo GODROP USER TestUser In my Test scenario I used the below queries: ALTER AUTHORIZATION ON SCHEMA::db_securityadmin TO dbo;ALTER AUTHORIZATION ON SCHEMA::db_ddladmin TO dbo; GO DROP USER TestUser Hope this helps. Cheers, Subhro Saha Subhro's BlogGoogle Related Post navigation ← Previous post Next post → 1 thought on “SQL Server: Error: 15138-The database principal owns a schema in the database, and schema cannot be dropped!!” Pingback: How To Fix Error 15138 Sql Server Errors - Windows Vista, Windows 7 & 8 Leave a Reply Cancel reply Enter your comment here... Fill in your details below or click an icon to log in: Email (Address never made public) Name Website You are commenting using your WordPress.com account. (LogOut/Change) You are commenting using your Twitter account. (LogOut/Change)
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top The database principal owns a schema in the database, and cannot be dropped message up vote 15 down vote favorite 3 I am trying to delete a principal from the database but can't because it owns a schema. When I go to edit the user, however, the box to uncheck schemae is blue and unremovable. How can I remove the principal from these schemas? sql-server sql-server-2008 share|improve this question edited Jun 18 '12 at 18:25 Thomas Stringer 31.7k573117 asked Jun 18 '12 at 17:54 rsteckly 306139 add a comment| 2 Answers 2 active oldest votes up vote 12 down vote accepted Try the T-SQL to do this: alter authorization on schema::YourSchemaName to dbo go drop user TheUserYouWantToDelete go You can't drop a principal that is a schema owner, so the ALTER AUTHORZATION changes the owned schema (I used YourSchemaName, but obviously substitute that with the owned schema in your database) to dbo (likewise, you can change ownership to whatever principal you need in your environment). That will allow you to drop the previously-schema-owning user (for example purposes I used TheUserYouWantToDelete,