Restore Database with T-SQL

--Easy to do, the alter commands are so the database disconnects all users and can be restored--




alter database <DBName> set single_user with rollback immediate

RESTORE database <DBName> FROM DISK = 'C:\temp\<DBName>.bak' database <DBName> set single_user with rollback immediate

RESTORE database <DBName> FROM DISK = 'C:\temp\<DBName>.bak' database <DBName> FROM DISK = 'C:\temp\<DBName>.bak'

WITH MOVE 'PrimaryFileName' TO 'C:\<Path>\<DBName>.mdf', MOVE 'PrimaryFileName' TO 'C:\<Path>\<DBName>.mdf',

MOVE 'PrimaryLogFileName' TO 'C:\<Path>\<DBName>_log.ldf',STATS = 1, REPLACE 'PrimaryLogFileName' TO 'C:\<Path>\<DBName>_log.ldf',STATS = 1, REPLACE

alter database <DBName> set multi_user database <DBName> set multi_user

Comments

Popular posts from this blog

Metastorm - Open form in an action from a list or link

Corporate Intranet Information Architecture – a Publishing Site

No Search Results in SharePoint Contextual Search OSSSearchResults.aspx