MSSQL: Drop login but get error
Server principal 'DB_A667B6_kofoglu_admin' has granted one or more permission(s). Revoke the permission(s) before dropping the server principal. (Microsoft SQL Server, Error: 15173)
Since DB_A667B6_kofoglu_admin exists only as a login at Server level, we query if DB_A667B6_kofoglu_admin has granted permissions to any other Server Principal using the following script :
Select * from sys.server_permissions
where grantor_principal_id =
(Select principal_id from sys.server_principals where name = N'DB_A667B6_kofoglu_admin')
Output
class class_desc major_id grantee_id grantor_id Type Permission_name state state_desc
101 SERVER_PRINCIPAL 4979 2 4979 VW VIEW DEFINITION G GRANT
2 was the principal_id for ‘public’
4979 was the principal_id for ‘DB_A667B6_kofoglu_admin’
How to know the above? Use the following script:
SELECT pr.principal_id, pr.name, pr.type_desc,
pe.state_desc, pe.permission_name
FROM sys.server_principals AS pr
JOIN sys.server_permissions AS pe
ON pe.grantee_principal_id = pr.principal_id;
find the principal_id and name from the generated table
you can verify the grantee from SSMS UI or execute the following script to revoke the permission.
REVOKE VIEW DEFINITION ON LOGIN:: DB_A667B6_kofoglu_admin FROM [public]
USE MASTER
REVOKE VIEW DEFINITION ON LOGIN:: DB_A667B6_kofoglu_admin FROM [public]
Make sure all output permission was revoked, you can now drop the login successfully.