Skip to content

Instantly share code, notes, and snippets.

@davidisnotnull
Created August 20, 2020 06:51
Show Gist options
  • Save davidisnotnull/4667c70f21f825d42ba90a6002ae0a94 to your computer and use it in GitHub Desktop.
Save davidisnotnull/4667c70f21f825d42ba90a6002ae0a94 to your computer and use it in GitHub Desktop.
Drop all Users in database
--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