ApexSQL Build Command Line Interface (CLI) switches

Applies to
ApexSQL Build

Summary
This article explains the ApexSQL Build CLI switches, and their usage through the examples

Description

Connection switches

/serverSpecifies server and instance name of the source SQL instance
Alias: /s
Format: /server:server_name[\instance_name]
Quick tip icon

Quick tip:

If a server is not specified (local) instance is assumed

/databaseSpecifies the name of the database to connect to
Alias: /d
Format: /database:DatabaseName
Quick tip icon

Quick tip:

If a database name is not specified DefaultDb will be used

/userSpecifies the login when using SQL Server authentication
Alias: /u
Format: /user:login
Note: You must use this option together with the
/password switch
Quick tip icon

Quick tip:

If a /user is not specified a trusted connection is assumed

/passwordSpecifies the login when using SQL Server authentication
Alias: /p
Format: /password:pa$$w0rd
Note: You must use this option together with the /user switch

Create database switches

/database_scriptFull path to a script that will be used for creating a database (with corresponding extension “.sql”)
Alias: /ds
Format: /database_script:”CreateDB.sql”
/database_
script_type
Specifies how database script will be created:

  • source _control [sc] – takes script from source control
  • scripts_folder [sf] – takes script from scripts folder
  • custom_scripts [cs] – takes custom script
  • from_application [fa] – create script in application

Alias: /dst
Format: /database_script_type:[sc|sf|cs|fa]
Note: These arguments cannot be combined

/db_dirThe MDF file of the database created by generated script will be created in the specified directory
Alias: /dbd
Format: /db_dir:”DatabaseFolderName”
/db_logdirThe LDF of the database created by generated script will be created in the specified directory
Alias: /dbld
Format: /db_logdir:”DatabaseLogDirectory”
/db_collationSpecifies the database collation
Alias: /dbc
Format: /db_collation:Latin1_General_CI_AS
/db_recoverySpecifies the recovery mode for the database:

  • Simple
  • Full
  • Bulklogged

Alias: /dbrv
Format: /db_recovery:[Simple|Full|Bulklogged]
Note: These arguments cannot be combined
Omitting this switch will result in setting simple as a default recovery mode

/db_sizeSpecifies the size for the database in KB, MB, or GB
Alias: /dbs
Format: /db_size:1024KB
/drop_if_existsChecks if database exists and drops it
Alias: /die
Format: /drop_if_exists

Script switches

/include_
static_data
Include static data from loaded input source into tables
Alias: /isd
Format: /include_static_data
/invalid_objectsEnforces deferred name resolution. When it is used, a warning will be generated if an invalid object is referenced by a procedure.
Alias: /io
Format: /invalid_objects
/include_
transaction
Wrap the created script statements into explicit transactions. Any errors that occur during the script execution will roll back the transactions and leave the database in the state it was before the statements were executed
Alias: /ith
Format: /include_transaction
/script_ansi_
options
Add the SET ANSI_PADDING ON/OFF and SET ANSI_NULLS ON/OFF options to the output script before each object is affected
Alias: /sao
Format: /script_ansi_options
/script_dropsAdd DROP statements to the output script for each object before the corresponding CREATE statement is scripted
Alias: /sdr
Format: /script_drops
/script_
collation
Add collation scripts for character columns to the output script in CREATE TABLE statements
Alias: /sc
Format: /script_collation
/script_extended_
properties
Script extended properties for object types where applicable
Alias: /sep
Format: /script_extended_properties
/script_filegroupsScript available database filegroups with the existence check
Alias: /sfg
Format: /script_filegroups
/script_loginsScript SQL Server logins that the scripted database users are based on
Alias: /slg
Format: /script_logins
/script_namesScript index, foreign key and constraint names
Alias: /snm
Format: /script_names
/script_
permissions
Scripts permissions granted, denied or revoked on objects where applicable
Alias: /sp
Format: /script_permissions
/script_triggersScript existing table/view triggers along with the parent object
Alias: /str
Format: /script_triggers
/script_useAdd USE <database name> statements to the output scripts
Alias: /su
Format: /script_use
Quick tip icon

Quick tip:

If a /database_script_type is not specified from_application is assumed

Specific switches

/projectFull path to the project file, along with the “.axbd” extension
Alias: /pr
Format: project:”ProjectFile.axdb”
Quick tip icon

Quick tip:

If a project file is saved outside of the installation directory, specify the path where it’s located

/project_typeSpecifies project type:

  • build_db [bdb] – build a new database
  • update_db [udb] – update an existing database
  • consolidate_scripts [cs] – consolidate scripts

Alias: /pt
Format: /project_type:[bdb|udb|cs]
Note: These arguments cannot be combined.
If omitted, build_db is assumed

/output_typeSpecifies output type:

  • database [db] – database output format
  • sql [s] – SQL output format
  • csharp [cs] – C# solution
  • exe_installer [ei] – executable installer

Alias: /ot
Format: /output_type:[db|s|cs|ei]
Note: These arguments cannot be combined.
If omitted, database is assumed

/output_nameFull path to an output file or folder folder (“Build_script_%date%_%time%.sql” filename, “Package_%date%_%time%.exe” filename or “Package_%date%_%time%” folder if omitted)
Alias: /on
Format: /output_name:”Build_script_%date%_%time%.sql”
/source_typeSpecifies source type:

  • sql [s] – SQL script input format
  • script_folder [sf] – scripts folder input format
  • snapshot [sn] – database snapshot input format
  • sourcecontrol [sc] – source control input format

Alias: /st
Format: /source_type:[s|sf|sn|sc]
Note: These arguments cannot be combined.
If omitted, sql is assumed

/source_nameFull path to source file (with corresponding extension “.sql” or “.axsnp”) or folder, except for source control (use source control options for source input)
Alias: /sn
Format: /source_name:”SnapshotFile.axsnp”
/output_
action_type
Specifies output action type:

  • create – create a new database
  • create_execute – create a new database and execute it

Alias: /oat
Format: /output_action_type:
[create|create_execute]

Note: These arguments cannot be combined.
If omitted, create_execute is assumed

/compatibility_
level
Sets database compatibility level:

  • None
  • SQL2005
  • SQL2008
  • SQL2012
  • SQL2014
  • SQL2016
  • SQL2017
  • AzureSQLDatabase

Alias: /cl
Format: /compatibility_level:[none|SQL2005
|SQL2008|SQL2012|SQL2014|SQL2016|SQL2017
|AzureSQLDatabase]

Note: These arguments cannot be combined

/postscript_
file_path
Full path to the post-deployment script, along with the “.sql” extension
Alias: /postfp
Format: /postscript_file_path:”PostScript.sql”
/output_elementsSpecifies a set of the optional output elements:

  • None [n]
  • Author [a]
  • DateTime [dt]
  • Legal [l]
  • Comments [cmt]
  • PrintStatements [ps]
  • Default [dft] – Combination of Comments and PrintStatements

Alias: /oe
Format: /output_elements:[a|dt|l|cmt|ps]
Note: Arguments can be combined.
The Author and Legal values must be used together with the /author and /legal switches

/authorSpecifies the name of author in the header of the comparison report or the synchronization script
Alias: /auth
Format: /author:”John Doe”
Note: If the /author switch is specified, its dependent switch and value /output_elements:a need to be provided
/legalSpecifies the legal information in the header of the comparison report or the synchronization script
Alias: /leg
Format: /legal:”© ApexSQL LLC”
Note: Note: If the /legal switch is specified, its dependent switch and value /output_elements:l need to be provided

Source control switches

/sourcecontrol_
type
Type of source control used as the source:

  • git
  • mercurial
  • perforce
  • subversion
  • teamfoundationserver

Alias: /sct
Format: /sourcecontrol_type:[git|mercurial|subversion|
perforce|teamfoundationserver]

Note: These arguments cannot be combined

/sourcecontrol_
user
Source control username
Alias: /scu
Format: /sourcecontrol_user:sc_login

/sourcecontrol_
password
Source control password (used with /sourcecontrol_user switch)
Alias: /scp
Format: /sourcecontrol_password:sc_password

/sourcecontrol_
server
Name of the source control server (TFS server, Perforce host)
Alias: /scs
Format: /sourcecontrol_server:
[<protocol>://<hostname>:<portname>/tfs|
https://<accountname>.visualstudio.com/
DefaultCollection
(example for Team Foundation Server)

Format: /sourcecontrol_server:
[<protocol>://<hostname>:<portname>
(example for Perforce)

/sourcecontrol_
repository
Repository of the source control server (Git, Mercurial, Subversion repository, and Perforce depot)
Alias: /scr
Format: /sourcecontrol_repository:
<protocol>://<hostname>:
<portnumber>/<git_server_name>
(example for Git repository)

Format: /sourcecontrol_repository:
<protocol>://<hostname>:
<portnumber>/<repository>/
(example for Mercurial repository)

Format: /sourcecontrol_repository:
<protocol>://<hostname>:
<portnumber>/svn/<repository>/
(example for Subversion repository)

/sourcecontrol_
branch
Branch name for Git source control type (“master” if omitted)
Alias: /scb
Format: /sourcecontrol_branch:”branch_name”

/sourcecontrol_
project
Project path containing script files on the source control server (Git, Mercurial, Subversion, TFS folder, Perforce workspace)
Alias: /scj
Format: /sourcecontrol_project:”$/ProjectName”

/sourcecontrol_
label
Get script files from the source control project used as the source by label (get latest sources if omitted)
Alias: /scl
Format: /sourcecontrol_label:”LabelName”

/sourcecontrol_
folder
Path of a local working folder with script files (when source control is used as the source)
Alias: /scf
Format: /sourcecontrol_folder:”SourceControlFolder”

Package switches

/package_
compression
Reduces the size of the resulting executable by using compression
Alias: /pkcm
Format: /package_compression
/package_errorSets the package error handling:

  • Abort – package execution is aborted and all changes are rolled back
  • Ignore – all errors are ignored during the package execution
  • Ask – user confirmation is required for each encountered error, whether to abort or continue the package execution

Alias: /pke
Format: /package_error:[Abort|Ignore|Ask]
Note: These arguments cannot be combined.
If omitted, ask is assumed

/package_authorPlaces the author tag into the about box of the package.
Alias: /pkaa
Format: /package_author:”Author_name”
/package_companyPlaces the company tag into the about box of the package.
Alias: /pkco
Format: /package_company:”Company_name”
/package_legalPlaces the legal tag into the about box of the package
Alias: /pkal
Format: /package_legal:”Legal_notice”
/package_commentsPlaces the comments tag into the about box of the package
Alias: /pkac
Format: /package_comments:”Comments”
/vs_verSets package Visual Studio version:

  • VS2005
  • VS2008
  • VS2010
  • VS2012
  • VS2013
  • VS2015
  • VS2017

Alias: /vrv
Format: /vs_ver:[VS2005|VS2008|VS2010|VS2012|VS2013|VS2015|VS2017]
Note: These arguments cannot be combined.
If omitted, VS2017 is assumed

/create_mfsCreates a manifest file that contains the information regarding OS compatibility versions and sets the Windows user account control level to allow the application to run without any additional permissions
Alias: /cmf
/create_datCreates a .dat file which contains SQL code for creating new or updating the existing database
Alias: /cdf
/create_comCreates a CLI (Command Line Interface) executable for package.
Alias: /ccf

Learn more about additional switches from article on this link.

Return codes

Learn more about common return error codes from the article on this link.

Examples

Note: All examples assume that the current directory is the application directory. If not, the full path to ApexSQLBuild.com must be specified.

Create new database (which will be named DefaultDb, by default) and execute it on LocalServer from the script file named SQLQuery3:

ApexSQLBuild.com /ot:db /sn:”SQLQuery3.sql”

Create new database named TestDb2017 on LocalServer, where permissions and extended properties will be scripted, from the script folder named 2008SF:

ApexSQLBuild.com /ot:db /d:TestDb2017 /sp /sep /st:sf /sn:”2008SF” /oat:create

Create an executable installer for the new database named PartialDB, where previous database will be dropped if exists, from a snapshot file and including static data, with compatibility level SQL 2012:

ApexSQLBuild.com /pt:bdb /ot:ei /d:PartialDB /die /st:sn /sn:”ADW2014.axsnp” /isd /cl:SQL2012

Consolidate scripts into one script by using a project file and specifying its path, overwrite an existing file of the same name, and verbose messages that are generated during the script processing:

ApexSQLBuild.com /pr:”ProjectFile.axbd” /f /v

Create new database from the source control repository using a Git server as an input source on a local server and database named GitDB:

ApexSQLBuild.com /pt:bdb /ot:db /d:GitDB /st:sc /sct:git /scu:SourceControlUser /scp:scpass /scr:”https://Ivana@bitbucket.org/Ivana/Build.git” /scj:”$/Build”

Using an argument file, e.g. “ArgFile.xml”, to execute commands:

ApexSQLBuild.com /argfile:”ArgFile.xml”

Create new database on the server with SQL Server authentication where all database options will be customized:

ApexSQLBuild.com /s:servername /u:user /p:pass /d:NewDatabase /dbd:C:\DBS /dbld:”LogDir” /dbc:Latin1_General_CI_AI_KS_WS /dbrv:Full /dbs:”10 MB” /die

Update an existing database which will be created and executed from a snapshot file, with a drop if exist and include static data options:

ApexSQLBuild.com /pt:udb /ot:db /st:sn /die /isd /oat:create_execute /sn:”ADW2014.axsnp”