Archive

Archive for the ‘SQL’ Category

MSSQL Restore locked database

October 18th, 2011 No comments

Below is a short snippet that will allow you to restore your database by putting it in single user mode.
After restoring (if without errors) it will be in multi user mode again. If it is not you can still run the ‘alter database DATABASE_NAME set multi_user’ command to put it back in original mode.

USE master;
 
ALTER DATABASE [DATABASE_NAME] SET single_user WITH ROLLBACK immediate;
 
restore DATABASE [DATABASE_NAME] FROM disk = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\YOUR_AWESOME_BACKUP.bak';
Categories: SQL Tags: , ,

MSSQL Changing login for user

October 18th, 2011 No comments

Sometimes when you move a database to another server it is necessary to change the login for a user to match the new environment. You can use the alter user command to do this. Do something like the following:

ALTER USER [THE_USER_NAME] WITH NAME = NEW_USER_NAME, LOGIN = [MACHINENAME\NEW_USER_NAME];

Not really complicated, but handy when you need it. 🙂

Categories: SQL Tags: , ,