Last active
August 29, 2015 14:02
-
-
Save deadlydog/8eb83a0f19685f9d5513 to your computer and use it in GitHub Desktop.
Loop through every SQL Server database on server, create user if they don't exist, and set that user's permissions
This file contains 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
exec master.dbo.sp_foreachdb | |
'USE ? | |
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = ''Domain\UserOrGroup'') | |
BEGIN | |
CREATE USER [Domain\UserOrGroup] FROM LOGIN [Domain\UserOrGroup] | |
END | |
exec sp_addrolemember ''db_backupoperator'', ''IQMETRIXHO\Development''; | |
' | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment