15138 Sql Error
Contents |
| Related Tips: More > Security Problem Recently I had an issue while dropping an orphaned user for an obsolete login. I was unable to drop the user and it failed with the below error messages. Msg 15421, Level sql error 18456 16, State 1, Line 1 The database principal owns a database role and cannot be dropped. sql error 15023 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 sql error 15128 I will explain what needs to 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: sql server error 15138 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 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
Msg 15138 Sql Server
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-> Right Click on the database role that you need to modify. You can see the user name "Jugal" as the owner. Change it to "dbo" or some other user to resolve the error. You can just enter the user and click OK to save the change or click on the "..." to find a user. Using a Script to Fix the Error Here we are transferring ownership of the "db_owner" role to "dbo". --Query to fix the error Msg 15138 USE [db1] GO ALTER AUTHORIZATION ON ROLE::[db_owner] TO [dbo] GO Fix Error Msg 15138 Using SSMS to Fix the Error Go to
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 15138, sys.schemas Today one of
Remove User From Schema Sql Server
my reader asked a question about how to fix the error while the database principal owns a database role and cannot be dropped trying to remove a login from a database. The reader was getting the below error: Msg 15138, Level 16, the database principal owns a service in the database and cannot be dropped State 1, Line 1The database principal owns a schema in the database, and cannot be dropped. The error message of SQL Server is self explanatory as there were schema associated with the https://www.mssqltips.com/sqlservertip/2620/steps-to-drop-an-orphan-sql-server-user-when-it-owns-a-schema-or-role/ 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 we are trying to drop the user. Use DemoDB ;SELECT s.nameFROM sys.schemas sWHERE s.principal_id = USER_ID(‘TestUser') 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/ 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) You are commenting using your Facebook account. (LogOut/Change) You are commenting using your Google+ account. (LogOut/Change) Cancel Connecting to %s Notify me of new comments via email. Notify me of new p
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 List all Disabled Indexes in a SQL Server http://zarez.net/?p=179 Database How to Disable and Enable Index in SQL Server SQL Server Buffer Pool Memory used by https://social.msdn.microsoft.com/Forums/sqlserver/en-US/67ce8ae7-d47c-4515-9929-92d2a516934a/can-not-drop-user-from-database?forum=sqlsecurity each Object and each Database SQL Server Views WITH CHECK OPTION See the 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 of a Month in SQL Server Concatenate SQL Server Columns that contain NULL values How sql error 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 database you will get the following error: The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, the database principal 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 9, 2014 at 8:54 am · Reply Hey man, Thanks for this hint!! It works fine! Greetings from Germany Robby Salomon September 26, 2014 at 2:29 pm · Reply Thanks man! This works All the best, Robby tryden March 20, 2015 at 7:30 pm · Reply Worked perfectly
(Русский)ישראל (עברית)المملكة العربية السعودية (العربية)ไทย (ไทย)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語) HomeLibraryLearnDownloadsTroubleshootingCommunityForums Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: can not drop user from database SQL Server > SQL Server Security Question 2 Sign in to vote I can not delete user from a database in sql2005 beta 3.the message errror is :TITLE: SQL Server Management Studio---------------------------------------- Drop failed for User 'Amministratore'. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft SQL Server&ProdVer=9.00.0981.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+User&LinkId=20476 ----------------------------------------ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ---------------------------------------- The database principal owns a schema and cannot be dropped. (Microsoft SQL Server, Error: 15138) in sql 2000 I can delete the user very easy, but in sql 2005 I don't understant How to do it. Wednesday, October 12, 2005 9:42 AM Reply | Quote Answers 7 Sign in to vote You can query the catalogs. For example, you can execute the following query: select * from sys.objects where schema_id = schema_id('s') to find out the objects that reside in schema 's'. ThanksLaurentiu Thursday, January 05, 2006 1:01 AM Reply | Quote Moderator 6 Sign in to vote In SQL Server 2005, schemas are real entities. You cannot drop a user that owns schemas; you first have to either drop the schemas or change their owner to be another user.ThanksLaurentiu Wednesday, October 12, 2005 5:13 PM Reply | Quote Moderator 1 Sign in to vote Before dropping a schema, it must be empty. Looks like in your case, you still have an object in the schema: Alert_List. You may either choose to drop this object first or you may choose to move it to another schema (using ALTE