Tuesday, May 3, 2016

SQL match orphaned users after DB restore

Restoring a DB to another DB server will not restore users to the SQL server itself, only the users in the DB.  But to use those users, they will need to be created in the SQL server and then mapped to the appropriate user in the DB.

Quick notes on how to do this.

List the orphaned users:
use RestoredDBName
EXEC sp_change_users_login 'Report'

Fix the users
use RestoredDBName
EXEC sp_change_users_login 'Auto_Fix', 'user'
-or-
EXEC sp_change_users_login 'Update_One', 'OrphanedUser', 'OrphanedUser'


More Details here.
https://msdn.microsoft.com/en-us/library/ms174378.aspx

No comments:

Post a Comment