USEmaster–(Cantsitinthedatabasewhilstitsbeingrestored!)
GO
ALTERDATABASEMyDatabaseSETSINGLE_USERWITHROLLBACKIMMEDIATE
GO
–RestoreFullBackup
RESTOREDATABASEMyDatabase
FROMDISK=x:\MSSQL\BACKUP\MyBackupFilename_Full.BAK
WITH
REPLACE,NORECOVERY,–UseifmoreT/Logstorecover
–RECOVERY,–UseifNOmoreT/Logstorecover
STATS=10,–Showprogress(every10%)
MOVEMyDatabase_DataTOx:\MSSQL\DATA\MyDatabase.mdf,MOVEMyDatabase_LogTOx:\MSSQL\DATA\MyDatabase.ldf
GO
–OptionalrestoreDifferentialBackup
RESTOREDATABASEMyDatabase
FROMDISK=x:\MSSQL\BACKUP\MyDatabase_Diff.BAK
WITH
–RECOVERY–UseifNOmorefiletorecover
NORECOVERY–UseifthereareT/Logstorecover
GO
–OptionalrestoreTransactionLogBackup
RESTOREDATABASEMyDatabase
FROMDISK=x:\MSSQL\BACKUP\MyDatabase_yyyymmdd_hhmm_Trans.BAK
WITH
–RECOVERY–UseifNOmoreT/Logstorecover
NORECOVERY–UseifmoreT/Logstorecover
GO
–Setthedatabasereadyforuse(afterallbackupshavebeenrestored)
RESTOREDATABASEMyDatabaseRECOVERY
GO
–Renamelogicalnames(onlyneededifrestoringfromabackupforaDifferentdatabase):
ALTERDATABASEMyDatabase
MODIFYFILE(NAME=OrigDatabase_Data,NEWNAME=MyDatabase_data)
GO
ALTERDATABASEMyDatabase
MODIFYFILE(NAME=OrigDatabase_Log,NEWNAME=MyDatabase_log)
GO