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
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
Post a Comment