SQL Server Schema-only Backup
Published 25 November 2024
This document outlines the steps required to create a schema-only backup of a database. The backup can then be used to baseline a project, see Backups as baselines for more information.
1 - Create a schema only copy of the database
The DBCC CLONEDATABASE command creates a schema-only, read-only copy of a database. The example below creates a schema-only copy of the AdventureWorks2022
database called AdventureWorks2022_Copy:
DBCC CLONEDATABASE(AdventureWorks2022, AdventureWorks2022_Copy) with VERIFY_CLONEDB;
The VERIFY_CLONEDB
argument verifies the consistency of the new AdventureWorks2022_Copy database. Please see here for more information about the limitations of DBCC CLONEDATABASE
command and the list of objects it supports.
2 - Create a backup of the copied database
Once a schema-only copy of the database exists, then a backup of that database can be created. The example below creates a backup of the AdventureWorks2022_Copy
database and saves it in the /var
folder:
BACKUP DATABASE [AdventureWorks2022_Copy] TO DISK = N'/var/AdventureWorks2022_Copy.bak';
3 - Drop the copied database
Once the backup exists, the copied database is no longer needed and can be dropped:
DROP DATABASE [AdventureWorks2022_Copy];