Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop a SQL Server user with db owner privilege

I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message

Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

When I try to uncheck the schema owned by this user to remove the DB owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITY\NETWORK SERVICE'

like image 323
Sofia Khwaja Avatar asked Feb 16 '16 13:02

Sofia Khwaja


People also ask

Can db_owner drop database?

Members of the db_owner fixed database role can perform all configuration and maintenance activities on the database, and can also drop the database in SQL Server.

What command would you use to remove a user from a SQL Server?

The DROP USER statement is used to remove a user from the SQL Server database.

How do I Delete an orphaned user in SQL Server?

Once you have identified orphan users it is extremely simple to remove them. You remove them by using the sp_revokeuser SP. Here is an example that removes the database users 'USERX', from the current database in use.


2 Answers

I had the same problem, i run two script then my problem is solved.

try this:

In this query you can get user schema as a result for AdventureWorks database

USE AdventureWorks; SELECT s.name FROM sys.schemas s WHERE s.principal_id = USER_ID('your username'); 

after take schema name you can alter authorization on schema like this:

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo; 

in this query db_owner schema name that get from first query.

finally you can delete user without error.

my source: SQL SERVER – Fix: Error: 15138

like image 126
Hasan Fathi Avatar answered Sep 21 '22 07:09

Hasan Fathi


I have the same issue, I cannot delete the user

foo

since it says:

enter image description here

So I need to go to Security -> Schemas and look for dbo, then right click and choose Properties:

enter image description here

Then change

foo

to

dbo

then after that I can now delete the user that I want to delete.

enter image description here

like image 32
Willy David Jr Avatar answered Sep 22 '22 07:09

Willy David Jr