Some time we are trying to delete or drop a login from SQL server instance , we encountered with below error.
The server principal owns one or more server role(s) and cannot be dropped. (Microsoft SQL Server, Error: 15141)
Step 1) Find the server roles owned by login using below script
SELECT sp1.name AS ServerRoleName,
sp2.name AS RoleOwnerName
FROM sys.server_principals AS sp1
JOIN sys.server_principals As sp2
ON sp1.owning_principal_id=sp2.principal_id
WHERE sp2.name='Test' --Change the login name
Step 2 ) Change server role to another login
USE [master]
GO
ALTER AUTHORIZATION ON SERVER ROLE :: Admin to SQLAdmin
Step 3) Drop login
USE [master]
GO
Drop Login Test
No comments:
Post a Comment