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
/passwordSpecifies the login when using SQL Server authentication
Alias: /p
Format: /password:password
Note: You must use this option together with the /user switch
Quick tip icon

Quick tip:

If a user is not specified a trusted connection is assumed

Create database switches

/db_dirThe MDF file of the database created by generated script will be created in the specified directory
Alias: /dbd
Format: /db_dir:D:\FolderName
/db_logdirThe LDF of the database created by generated script will be created in the specified directory
Alias: /dbld
Format: /db_logdir:log_directory
/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

Script switches

/script_dropsAdd DROP statements to the output script for each object before the corresponding CREATE statement is scripted
Alias: /sdr
Format: /script_drops
/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_collationAdd collation scripts for character columns to the output script in CREATE TABLE statements
Alias: /sc
Format: /script_collation
/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_triggersScript existing table/view triggers along with the parent object
Alias: /str
Format: /script_triggers
/script_permissionsScripts permissions granted, denied or revoked on objects where applicable
Alias: /sp
Format: /script_permissions
/script_extended_
properties
Script extended properties for object types where applicable
Alias: /sep
Format: /script_extended_properties
/script_useAdd USE <database name> statements to the output scripts
Alias: /su
Format: /script_use
/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
/commentsAdd comments to the output script before each object
Alias: /cm
Format: /comments
/print_statementsAdd PRINT statements to the output script before each object
Alias: /ps
Format: /print_statements
/database_scriptFull path to a script that will be used for creating a database (with corresponding extension “.sql”)
Alias: /ds
Format: /database_script:argument
Example: /ds: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

/drop_if_existsChecks if database exists and drops it
Alias: /die
Format: /drop_if_exists
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:argument
Example: /pr:Library.axbd
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 “db” is assumed

/output_nameFull path to a destination file (with corresponding extension “.sql” or “servername.databasename.exe”) or folder (“servername.databasename”)
Alias: /on
Format: /output_name:argument
Example: /on:Template.sql
/source_typeSpecifies source type

  • sql [s] – SQL 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:argument
Example: /sn:Library.axsnp
/output_action_typeSpecifies 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

/include_
static_data
Include static data into tables
Alias: /isd
Format: /include_static_data
Example: /pr:Library.axbd
/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
Example: /pr:Library.axbd
/compatibility_
level
Sets database compatibility level

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

Alias: /cl
Format: /compatibility_level:[none|SQL2005
|SQL2008|SQL2012|SQL2014|SQL2016
|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:LateScript.sql

Source control switches

/sourcecontrol_typeType 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:folder_path

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:C:\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:C:\2008SF /oat:create

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

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

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

ApexSQLBuild.com /pr:D:\Projects\ProjectFile.axbd /f /v

Create new database from the source control repository using a Git server:

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

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

ApexSQLBuild.com /argfile:FirstFile.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:C:\AppData /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:C:\ADW2014.axsnp