Ken,
Been a while since I worked with MSSQL, but just joined as I hope my next job takes me there again. Anyway I used this in 2003 and maybe 2005...
Apologies if I have blown all credibility on my 1st post.
Also Not sure if the @Action variable should be in single quotes or not.
-- ------------------------------------------------
-- Use this procedure to link the security account for a user in the current database with a different login or the same named login or the original login particularly when the link is lost after a database restore linking the user to the new login without losing the user's permissions. login cannot be sa, and user cannot be the dbo, guest, or INFORMATION_SCHEMA users.
-- ----------------------------------------------
--SYNTAX
--sp_change_users_login [ @Action = ] 'action'
-- [ , [ @UserNamePattern = ] 'user' ]
-- [ , [ @LoginName = ] 'login' ]
-- ----------------------------------------------
-- 'action' = Report
-- Lists the users, and their security identifiers (SID), that are in the database, not linked to any login.
EXEC sp_change_users_login @Action = 'Report'
-- -------------------------------------------------
-- 'action' = Auto_Fix
-- Links user entries in the sysusers table in the current database to logins of the same name in syslogins.
EXEC sp_change_users_login @Action = 'Auto_Fix'
-- ---------------------------------------------------
-- 'action' = [Update_One]
-- Links the specified user in the database to login. login must already exist. user and login must be specified.
sp_change_users_login @Action = Update_One , @UserNamePattern = 'user', @LoginName = 'login'
-- ---------------------------------------------------
-- IE If the login exists and is not linked just use it in the syntax
-- so if you want to connect old login 'Mary' with old user 'Mary' try this
EXEC sp_change_users_login @Action = Update_One, 'Mary', 'Mary'
--
-- IE: Change the login for an existing user
-- This example changes the link between user Mary in the pubs database and the existing login,
-- STEP 1: Add the new login NewMary
USE master
go
EXEC sp_addlogin 'NewMary'
go
--
-- STEP 2: Change the user account to link with the 'NewMary' login.
USE pubs
go
EXEC sp_change_users_login @Action = Update_One, 'Mary', 'NewMary'