I'm trying to figure out if there's a way to give a login whatever rights it needs to restore a database (e.g. DBCREATOR) and give the login the rights to map a different login to a user in the database after it was restored, without making it a sysadmin. I don't want the login to be a sysadmin because there will be certain databases it can't have rights to. Here's the script I was trying to use, and the result I was getting.RESTORE DATABASE mydb FROM DISK = '\\myserver\baselines\mydb.bak' WITH REPLACEUSE [mydb]IF EXISTS (SELECT * FROM sysusers WHERE [name] = 'mydb_user')BEGIN DROP USER mydb_userENDCREATE USER mydb_user FOR LOGIN mydb_userEXEC sp_addrolemember 'db_owner','mydb_user'
Result:Msg 916, Level 14, State 1, Line 1The server principal "test_login_dbcreator" is not able to access the database "mydb" under the current security context.
The only way I can think of to get around this is to use separate instances of SQL Server. Am I missing something?