Created
May 15, 2014 06:01
-
-
Save Greyeye/8b7b779a9babd81fc7a4 to your computer and use it in GitHub Desktop.
SQL user export (to setup mirror user)
http://www.mssqltips.com/sqlservertip/1166/login-failures-connecting-to-new-principal-after-sql-server-database-mirroring-failover/
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
SELECT | |
'create login [' + p.name + '] ' + | |
case when p.type in('U','G') then 'from windows ' else '' end + | |
'with ' + | |
case when p.type = 'S' then 'password = ' + master.sys.fn_varbintohexstr(l.password_hash) + ' hashed, ' + | |
'sid = ' + master.sys.fn_varbintohexstr(l.sid) + | |
', check_expiration = ' + case when l.is_expiration_checked > 0 then 'ON, ' else 'OFF, ' end + | |
'check_policy = ' + case when l.is_policy_checked > 0 then 'ON, ' else 'OFF, ' end + | |
case when l.credential_id > 0 then 'credential = ' + c.name + ', ' else '' end | |
else '' end + | |
'default_database = ' + p.default_database_name + | |
case when len(p.default_language_name) > 0 then ', default_language = ' + p.default_language_name else '' end | |
FROM sys.server_principals p | |
LEFT JOIN sys.sql_logins l ON p.principal_id = l.principal_id | |
LEFT JOIN sys.credentials c ON l.credential_id = c.credential_id | |
WHERE p.type in('S','U','G') | |
AND p.name <> 'sa' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment