Re-associate orphaned user with a login in SQL Server

Filed under: sql server

We've occassionally had issues when a login and a database user become disassociated. Both the login and user still exist but they are not connected.

When attempting to update it through Server -> Security -> User Mapping, you may get the following error:

User, group, or role \<USER\> already exists in the current database.

This is because the user mapping will attempt to create the user instead of adding an existing one to the mapping.

To resolve this, use the ALTER command on the user:

USE <DATABASE>
ALTER USER <USER> WITH LOGIN = <LOGIN>

Sources

SQL map a login to an existing user

© 2022 JASON RAE