When working with SQL Server Management Studio (SSMS), both Extract and Export operations deal with Data-Tier Applications (DAC), but serve distinct purposes:
-- Export DAC operation typically generates a .bacpac file
EXPORT DATABASE AdventureWorks TO DISK = 'C:\backups\AdventureWorks.bacpac'
-- Extract DAC operation generates a .dacpac file
EXEC msdb.dbo.sp_sysdac_extract_package
@package_name = 'AdventureWorksPackage',
@target_server_name = 'DEV-SQL01',
@package_data = @output_data OUTPUT
Export (BACPAC):
- Contains both schema and data
- Used for database migration or backup
- Creates portable database snapshots
Extract (DACPAC):
- Contains only schema (no data)
- Used for version control and deployment
- Enables schema comparison and updates
When to use Export:
Migrating a database between environments while preserving all data. For example, moving a production database to a staging server.
When to use Extract:
Deploying schema changes through CI/CD pipelines. The DACPAC can be used with SqlPackage.exe:
SqlPackage.exe /Action:Publish
/SourceFile:"AdventureWorks.dacpac"
/TargetServerName:"PROD-SQL01"
/TargetDatabaseName:"AdventureWorks"
Export operations typically take longer due to data movement. For a 50GB database:
- Export: ~2 hours (depending on hardware)
- Extract: ~5 minutes (schema-only)
Remember that DACPAC files support incremental deployments through schema comparison, while BACPAC files represent complete database states.
DACPAC files work particularly well with source control systems. A typical workflow might look like:
# PowerShell script for CI pipeline
$dacpac = SqlPackage /Action:Extract
/SourceConnectionString:"Server=.;Database=AdventureWorks"
/TargetFile:"AdventureWorks.dacpac"
git add AdventureWorks.dacpac
git commit -m "Schema version 2.1.0"
git push origin main
When working with SQL Server Data-Tier Applications (DAC) in SQL Server Management Studio (SSMS), you'll encounter two similar-sounding operations:
-- Extract creates a .dacpac file
EXEC msdb.dbo.sp_export_dac
@database_name = 'YourDatabase',
@package_name = 'C:\Backup\YourDatabase.dacpac'
-- Export creates a .bacpac file
EXEC msdb.dbo.sp_export_data_tier_application
@database_name = 'YourDatabase',
@package_name = 'C:\Backup\YourDatabase.bacpac'
The fundamental distinction lies in the output file formats:
- Extract (.dacpac): Contains only schema definitions (tables, views, stored procedures) without any data
- Export (.bacpac): Includes both schema and actual data from tables
Here's when to use each operation:
Extract (DACPAC) Scenarios
-- Ideal for schema migrations
-- Version control of database structure
-- Continuous integration/deployment pipelines
-- Comparing schemas between environments
Export (BACPAC) Scenarios
-- Full database backups with data
-- Migrating to Azure SQL Database
-- Creating test environments with sample data
-- Archiving complete database snapshots
The operations use different underlying SQL Server components:
-- DACPAC uses the Data-Tier Application Framework (DacFX)
-- BACPAC uses the SQL Server Import/Export Wizard components
-- Both can be automated through PowerShell:
# Extract DACPAC
Export-DaC -ServerInstance "localhost" -Database "YourDB" -OutputPath "C:\backup\YourDB.dacpac"
# Export BACPAC
Export-BaC -ServerInstance "localhost" -Database "YourDB" -OutputPath "C:\backup\YourDB.bacpac"
Key differences in execution:
- BACPAC operations are generally slower due to data transfer
- DACPAC files are smaller and faster to generate
- Network bandwidth affects BACPAC transfers significantly
- DACPAC supports schema verification on extraction
For developers working with both operations:
-- Combining both for full migrations
-- First extract schema
Export-DaC -ServerInstance "SRC_SERVER" -Database "ProdDB" -OutputPath "schema.dacpac"
-- Then export data
Export-BaC -ServerInstance "SRC_SERVER" -Database "ProdDB" -OutputPath "data.bacpac"
-- On target server
Import-DaC -ServerInstance "TGT_SERVER" -Database "TestDB" -DacPacPath "schema.dacpac"
Import-BaC -ServerInstance "TGT_SERVER" -Database "TestDB" -BacPacPath "data.bacpac"