SQL Server error 15138: User owns a schema, cannot be dropped
DROP USER failed because the user owns a schema (or other securable). Transfer ownership to another principal first, then drop the user.
- Error number
15138- Severity
- 16
- Category
- Permissions
What it means
A database user that owns a schema, role or other securable can't be dropped, because the object would be left without an owner. The message names the kind of object owned (for example owns a schema in the database).
Common causes
- The user owns a schema, often a schema with the same name created automatically for it.
- The user owns a database role or another securable.
How to fix it
-
Find what the user owns.
SELECT s.name AS schema_name FROM sys.schemas AS s WHERE s.principal_id = USER_ID(N'old_user'); SELECT r.name AS role_name FROM sys.database_principals AS r WHERE r.owning_principal_id = USER_ID(N'old_user');
-
Transfer ownership, then drop the user.
ALTER AUTHORIZATION ON SCHEMA::old_user TO dbo; DROP USER old_user;
Related errors
15151Object doesn't exist or no permission15023User, group, or role already exists2BP01PostgreSQL: dependent objects still exist
More permissions errors
916Login can't access the database229Permission denied on object262Permission denied in database15025The server principal already exists
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.