-- Tested with SQL Server 2000 (v8.0) /* Often, during a restoration of a database from a database backup performed on a different server, the user IDs in a database will not match login IDs on the server on which it's being restored. This is due to the SIDs not matching (due to two different SIDs existing on two different servers. This script will restore the SIDs for the users in the current database (if the database user names match the same names as those of the login IDs). NOTE: You MUST enable ad hoc system catalog changes for this script to work correctly. */ DECLARE @sid VARBINARY(85), @name SYSNAME; DECLARE c_Cursor CURSOR FAST_FORWARD FOR SELECT sid, name FROM sysusers; OPEN c_Cursor; FETCH NEXT FROM c_Cursor INTO @sid, @name; WHILE @@FETCH_STATUS = 0 BEGIN UPDATE master..sysxlogins set sid = @sid where name like @name; FETCH NEXT FROM c_Cursor INTO @sid, @name; END; CLOSE c_Cursor; DEALLOCATE c_Cursor;