33

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'

Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
Sofia Khwaja
  • 1,909
  • 3
  • 17
  • 20

4 Answers4

46

I had the same problem, I run two scripts 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

Majid
  • 13,853
  • 15
  • 77
  • 113
Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
  • 2
    This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar). – AcePL Aug 15 '18 at 15:43
  • 1
    This solution is work for me. Other solution to change owner - not work, user is steal launch error when I want to delete it. – Anton Nikolayevich Jun 29 '20 at 10:57
19

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

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
7

In my case I execute these commands and problem solved:

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;
ALTER AUTHORIZATION ON SCHEMA::db_datareader TO dbo;
ALTER AUTHORIZATION ON SCHEMA::db_datawriter TO dbo;
Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
Sayed Abolfazl Fatemi
  • 3,678
  • 3
  • 36
  • 48
-2
ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITY\SYSTEM] TO dbo
Thom A
  • 88,727
  • 11
  • 45
  • 75