question

seanthomas2010 avatar image
seanthomas2010 asked

sys.database_principals = null, removal with T-SQL

I would like to delete logins to which are of a null field in the DB, i am clearing down all unused logins and want to use the join below for the choice in tables SELECT DBUSER.NAME AS 'USER' --DB_NAME() as ''Database'', DBUser.NAME AS ''User'', DBRole.NAME as ''db_role'', s.[name] AS ''Login'' FROM sys.database_principals DBUser JOIN sys.database_role_members DBM ON DBM.member_principal_id = DBUser.principal_id JOIN sys.database_principals DBRole ON DBRole.principal_id = DBM.role_principal_id LEFT JOIN sys.server_principals s on DBUser.sid = s.sid WHERE s.[name] IS NULL ORDER BY DBUSER.NAME ASC;
sql-server-
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.