Last active
May 26, 2020 14:09
-
-
Save JosiahSiegel/72e955ef927790ce6d66 to your computer and use it in GitHub Desktop.
#MSSQL #Users Link database user with login
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
USE [AdventureWorks] | |
GO | |
ALTER USER [Joe] WITH LOGIN = [Joe] | |
GO |
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
DECLARE @command NVARCHAR(MAX) | |
SELECT @command = | |
N'IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'') | |
BEGIN | |
USE [?] | |
ALTER USER [user] WITH LOGIN = [user] | |
END | |
' | |
EXEC sp_MSforeachdb @command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment