Created
August 20, 2020 06:51
-
-
Save davidisnotnull/4667c70f21f825d42ba90a6002ae0a94 to your computer and use it in GitHub Desktop.
Drop all Users in database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Drop all Users in database | |
DECLARE @sql NVARCHAR(max) | |
SET @sql = '' | |
SELECT @sql = @sql+ | |
' | |
print ''Dropping '+name+''' | |
drop user ['+name+'] | |
' | |
FROM | |
dbo.sysusers | |
WHERE | |
name NOT IN('dbo','guest','INFORMATION_SCHEMA','sys','public') | |
AND LEFT(name,3) <> 'db_' | |
ORDER BY | |
name | |
print @sql | |
execute ( @sql ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment