This is related to my previous post..

Differential Backup Issue - Why? Is this Possible?

Basically, the issue which I am having now is that in my restore process (as part of ETL), there are tasks to re-map db users to logins (because they are SQL Auth users in server A so lose mapping when restored on server B). Since restore with STANDBY will not allow this as it will be read-only db.. how can I get around this..?


2 Answers 2


Your users from db on server A will be moved to the database on server B with the backup. Then all you need is to recreate the logins with the same sid. You do this using WITH SID option:

CREATE LOGIN My_login WITH SID = 0x14585E90117152449347750164BA00A7

the sid obviously is your user sid that you can find in sys.database_principals:

select name, sid
from sys.database_principals
where type_desc = 'SQL_USER';
  • for clarity, I need to run select name, sid from sys.database_principals where type_desc = 'SQL_USER'; on the source server (server A) then (re)create login on server B with that SID from server A. Is that correct? Jul 29, 2017 at 8:16
  • Yes, it's correct. Or instead you can run this script in database on server B: it has exactly same user with exactly same SIDs
    – sepupic
    Jul 29, 2017 at 21:01

I find it easier to transfer logins via dbatools.io Copy-SQLLogin cmdlet if PowerShell is an option or sp_help_revlogin if not.

The Copy-SQLLogin cmdlet is a much easier approach and that link even has a video to help you step through the process, but again, if PowerShell isn't an option and you need to go the sp_help_revlogin route, make sure you execute that stored procedure (after you create via the linked article) on ServerA, copy the login statements over to ServerB and run the statement(s) there.

If you get an error, you may need to drop the existing user from ServerB first so that you can sync up the SIDs.

Finally, if you're running SQL 2012 or later, you may be able to configure your database to be a partially contained database instead. This will short-circuit things so the security is transferred with the backup as security is handled at the database level and not at the instance level. There are limitations to using partially contained databases, so review those first if you feel like this may be the approach you wish to take instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.