Skip to content

Latest commit

 

History

History
92 lines (58 loc) · 3.72 KB

File metadata and controls

92 lines (58 loc) · 3.72 KB
title SqlPackage.exe
description Learn how to automate database development tasks with SqlPackage.exe. View examples and available parameters, properties, and SQLCMD variables.
ms.prod sql
ms.prod_service sql-tools
ms.technology tools-other
ms.topic conceptual
ms.assetid 198198e2-7cf4-4a21-bda4-51b36cb4284b
author dzsquared
ms.author drskwier
ms.reviewer maghan; sstein
ms.date 11/4/2020

SqlPackage.exe

SqlPackage.exe is a command-line utility that automates the following database development tasks:

  • Version: Returns the build number of the SqlPackage application. Added in version 18.6.

  • Extract: Creates a database snapshot (.dacpac) file from a live SQL Server or Azure SQL Database.

  • Publish: Incrementally updates a database schema to match the schema of a source .dacpac file. If the database does not exist on the server, the publish operation creates it. Otherwise, an existing database is updated.

  • Export: Exports a live database - including database schema and user data - from SQL Server or Azure SQL Database to a BACPAC package (.bacpac file).

  • Import: Imports the schema and table data from a BACPAC package into a new user database in an instance of SQL Server or Azure SQL Database.

  • DeployReport: Creates an XML report of the changes that would be made by a publish action.

  • DriftReport: Creates an XML report of the changes that have been made to a registered database since it was last registered.

  • Script: Creates a Transact-SQL incremental update script that updates the schema of a target to match the schema of a source.

The SqlPackage.exe command line allows you to specify these actions along with action-specific parameters and properties.

Download the latest version. For details about the latest release, see the release notes.

Command-Line Syntax

SqlPackage.exe initiates the actions specified using the parameters, properties, and SQLCMD variables specified on the command line.

SqlPackage {parameters}{properties}{SQLCMD Variables}  

Usage examples

Generate a comparison between databases by using .dacpac files with a SQL script output

Start by creating a .dacpac file of your latest database changes:

sqlpackage.exe /TargetFile:"C:\sqlpackageoutput\output_current_version.dacpac" /Action:Extract /SourceServerName:"." /SourceDatabaseName:"Contoso.Database"

Create a .dacpac file of your database target (that has no changes):

sqlpackage.exe /TargetFile:"C:\sqlpackageoutput\output_target.dacpac" /Action:Extract /SourceServerName:"." /SourceDatabaseName:"Contoso.Database"

Create a SQL script that generates the differences of two .dacpac files:

sqlpackage.exe /Action:Script /SourceFile:"C:\sqlpackageoutput\output_current_version.dacpac" /TargetFile:"C:\sqlpackageoutput\output_target.dacpac" /TargetDatabaseName:"Contoso.Database" /OutputPath:"C:\sqlpackageoutput\output.sql"

Version

Displays the sqlpackage version as a build number. Can be used in interactive prompts as well as in automated pipelines.

sqlpackage.exe /Version

Exit codes

Commands that return the following exit codes:

  • 0 = success
  • non-zero = failure

Next steps