Link up Logins to Users in SQL Server
Here at Rackwire we are moving around SQL Server databases all the time. Whether it’s upgrades, new customers migrating to us, or setting up load balanced environments, we are often moving databases from one server to another doing a Backup-Restore. While this is fairly simple to do, one issue we often run into is having a User in a restored database that is not linked to the appropriate Login at the server level. As you may be aware, once a User gets created you cannot use the SQL Server Enterprise Manager tools to edit the Login it is linked to.
One way around that is to simply delete the User and recreate it. While that often works, many times the user will own objects, like tables, in the database and you cannot simply delete it. Luckily, there is a create Stored Procedure built into SQL Server that allows you to fix this problem without having to delete the User, it is SP_CHANGE_USERS_LOGIN. I find myself frequently using this stored procedure as it saves me a great deal of time. The usage of this is as follows:
Exec SP_CHANGE_USERS_LOGIN ‘Update_One’,'<Username>’,'<Login name>’;
It’s as simple as that. A quick and easy way to work around an annoying problem and save yourself some time.










