After performing a restore of a SQL Server (v12.0.2000) database, I figured that a user needs to be remapped to its login (this issue seems to be known as orphan users). And one of the simplest way to do it is to perform a :
use [MyDatabase];
alter user MyUser with login = MyUser;
Nevertheless, just after achieving a restore, the USE
command fails because I'm trying to execute the above command with 'MyUser'
, which is the one that is orphaned...
Because it is in a script, I would like to avoid performing a restore
with one user and a alter user
with another user, in order the first user be correctly remapped to its login.
Is there a way to do this with 'MyUser' (who could connect to master without problem) ?
I tried it by fully qualifying 'MyUser' the following way without success :
use master;
alter user MyDatabase.MyUser with login = MyUser;
Any idea if this is possible and how to do it ?
MyUser
should have permissions e.g. it should be a db_owner or if it has restore rights, then it should be able to runalter user .... with login
.