Home > Mobile >  SQL: Login 'abc' owns one or more databases(s)... Even though I just dropped those roles
SQL: Login 'abc' owns one or more databases(s)... Even though I just dropped those roles

Time:01-29

I'm trying to remove an SQL login with the following commands:

USE [myDB]
GO
ALTER ROLE [db_owner] DROP MEMBER [abc]
GO
USE [myDB]
GO
DROP USER [abc]
GO
USE [master]
ALTER SERVER ROLE [sysadmin] DROP MEMBER [abc]
GO
USE [master]
DROP LOGIN [abc]
GO

But SQL returns the following Error: Login 'abc' owns one or more database(s). Change the owner of the database(s) before dropping the login.

There are no other (Non-System-)Databases present on the server and i litterally just dropped the login from role DB_owner - what is going on?

CodePudding user response:

Users with the db_owner role is not the same as being the owner of the database.

You should use ALTER AUTHORIZATION to give ownership of the database to another principal.

If you get the user's SID then you can query the sys.databases catalog view (specifically the owner_sid column) to discover which databases they currently own.

  •  Tags:  
  • Related