domingo, 28 de octubre de 2012

Automatically Mapping a user to a login: sp_change_users_login

Sometimes we need to restore Databases in other servers, and logins probably doesn't exist on new server.
The restored Database contains Users and permissions but it aren't mapped with Logins.

Microsoft provides stored procedure to map user with login.
If login doesn't exist, Auto_Fix option will create it.

USE Database;
EXEC sp_change_users_login 'Auto_Fix', 'USER', NULL, 'Password';

Otherwise, if you only need to map USER with LOGIN, use the Update_One option:

USE Database;
EXEC sp_change_users_login 'Update_One', 'USER', 'LOGIN';

I hope that helps you.

No hay comentarios:

Publicar un comentario