Today when I was removing (deleting) some of the users from one of the SQL Server Database , got below error
The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)
The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)
Fig 1: Drop User from SQL Server Database Error
From the error message we can clearly tell that the user is the owner of schema. To take a detail look double click on the User in the database as shown below and see which schema is owned by this user.
Fig 2: Check The Owner Of Schema In SQL Server Database.
As we can see that mytestschema is the schema that is owned by user Aamir. To drop user 'Aamir' , we need to change the ownership of mytestschema to some other user. We can transfer the ownership to dbo. If you try to un-check the box for mytestschema , it will not work.
use this script to change the ownership of schema.
ALTER AUTHORIZATION ON SCHEMA::SchemaName TO dbo
For our case, it will be
use TestDB go ALTER AUTHORIZATION ON SCHEMA::mytestschema TO dbo
To drop the user , you can right click on user and Delete it or you can use below script to drop it.
USE DBName go Drop user UserName
ReplyDeletegood work done and keep update more.i like your information's and that is very much useful for readers.
Python Training in Chennai
Python course in Chennai
JAVA Training in Chennai
Big data training in chennai
Android Training in Chennai
Python Training in Chennai
Python Training in Anna Nagar
This comment has been removed by the author.
ReplyDeletethank you for valuable info
ReplyDeleteThis is Good information about this topic..I like it.. wordpress database errors ..Keep it Up!
ReplyDeleteInteresting Post. It is really Nice and lovely post. keep it up. keep blogging. otherwise anyone wants to learn SAS training course
ReplyDeleteSQL Server DBA Training in Bangalore