How to remap the user of a database to a particular login or to new login in SQL Server
Mostly at times of database migration projects, we do transfer the complete database to other server.
Users created in the database will also get migrated to the new server.
Logins are not yet migrated but users already exist in the database.
When we try to create the Login, it will throw an error but will get created successfully.
We have remap the login at that time so that login and user will have proper relationship.
To do so, Please execute the below command:
sp_change_users_login 'update_one','username','Loginname'
Going forward, in version of SQL Server above command may not work. So start using the below command :
alter user [username] with LOGIN [Loginname]
Mostly at times of database migration projects, we do transfer the complete database to other server.
Users created in the database will also get migrated to the new server.
Logins are not yet migrated but users already exist in the database.
When we try to create the Login, it will throw an error but will get created successfully.
We have remap the login at that time so that login and user will have proper relationship.
To do so, Please execute the below command:
sp_change_users_login 'update_one','username','Loginname'
Going forward, in version of SQL Server above command may not work. So start using the below command :
alter user [username] with LOGIN [Loginname]