Last active
October 5, 2021 21:02
-
-
Save psttf/7b43cdbd6782de1ad95153c65bc62359 to your computer and use it in GitHub Desktop.
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
-- since MSSQL 2008 use | |
-- ALTER USER OrphanUser WITH LOGIN = correctedLoginName; | |
DECLARE @uname varchar(30) | |
DECLARE curs1 CURSOR FOR | |
SELECT name | |
FROM sysusers | |
WHERE name <> 'dbo' AND issqluser = 1 AND hasdbaccess = 1 | |
ORDER BY name | |
OPEN curs1 | |
FETCH NEXT | |
FROM curs1 | |
INTO @uname | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
IF (@uname IS NOT NULL) AND (@uname <> 'guest') | |
BEGIN | |
PRINT @uname | |
EXECUTE sp_change_users_login Auto_Fix, @uname, NULL, 'autopass' | |
END | |
FETCH NEXT | |
FROM curs1 | |
INTO @uname | |
END | |
CLOSE curs1 | |
DEALLOCATE curs1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment