in Microsoft SQL Server

How to copy a MSSQL database

1. Backup the database

BACKUP DATABASE [database_name]
TO DISK = '[backup_filename]'

Make sure the MSSQL has access to write to [backup_filename]

2. Figure out the Data and Log names

RESTORE FILELISTONLY
FROM DISK = '[backup_filename]'

You will need to use the values for LogicalName in the next step

3. Restore the backup as a new database

RESTORE DATABASE [new_database_name]
FROM DISK = '[backup_filename]'
WITH MOVE '[LogicalName_1]' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\[new_database_name].mdf',
MOVE '[LogicalName_2]' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\[new_database_name]_log.ldf'

Replace C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\ with your MSSQL data file path.

  • Related Content by Tag