VanillaGranilla

dropUsersOrLogins.sql

Apr 9th, 2015
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.29 KB | None | 0 0
  1. --Drop User from all databases on a server -
  2. EXEC sp_Msforeachdb "IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N'USERNAME') DROP USER [USERNAME]"  
  3. GO  
  4.  
  5. --Drop the login -
  6. IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'USERNAME') DROP LOGIN [USERNAME]  
  7. GO
Advertisement
Add Comment
Please, Sign In to add comment