How to associate in Sql Server a database user with an existing Sql Server login

Note to self: Sometimes, when copying, restoring or attaching a database, sql server does not assign a login with a database user. Even when the login dependency is selected to be exported.

Everytime this happens, I have to search for the correct stored procedures. Not anymore:

use {mydbname}
EXEC sp_change_users_login 'Update_One', '{dbUserName}', '{loginName}'

EG:
USE outsystems
EXEC sp_change_users_login 'Update_One', 'OSAdmin', 'OSAdmin'

Leave a Reply