Get Data File Information from Backup File
RESTORE FILELISTONLY
FROM DISK = 'D:\SQLServerBackups\DEV_FULL_20200407.bak'
Drop Database
-- Place Database in Single User Mode
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDB01')
BEGIN
ALTER DATABASE MyDB01
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
END
GO
-- Drop Database
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDB01')
DROP DATABASE MyDB01
GO
Restore Database
RESTORE DATABASE MyDB01 FROM DISK = 'D:\SQLServerBackups\DEV_FULL_20200407.bak'
WITH FILE = 1, replace, maxtransfersize = 4194302, buffercount = 96, stats = 5,
MOVE 'MyDB01' TO 'D:\MSSQL\MyDB01\Data\MyDB01.mdf',
MOVE 'MyDB01_DATA' TO 'D:\MSSQL\MyDB01\Data\MyDB01_DATA.ndf',
MOVE 'MyDB01_INDEXES' TO 'D:\MSSQL\MyDB01\Index\MyDB01_INDEXES.ndf',
MOVE 'MyDB01_SET1_DATA' TO 'D:\MSSQL\MyDB01\Data\MyDB01_SET1_DATA.ndf',
MOVE 'MyDB01_SET1_INDEXES' TO 'D:\MSSQL\MyDB01\Index\MyDB01_SET1_INDEXES.ndf',
MOVE 'MyDB01_SET2_DATA' TO 'D:\MSSQL\MyDB01\Data\MyDB01_SET2_DATA.ndf',
MOVE 'MyDB01_SET2_INDEXES' TO 'D:\MSSQL\MyDB01\Index\MyDB01_SET2_INDEXES.ndf',
MOVE 'MyDB01_LOG' TO 'D:\MSSQL\MyDB01\Log\MyDB01_LOG.ldf'
Comments