ApexSQL Script Command Line Interface (CLI) switches

Applies to
ApexSQL Script

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

Description

Connection switches

/server Specifies 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

/database Specifies the name of the database(s) to connect to
Alias: /d
Format: /database:DatabaseName
Note: If you specify more than one database, then each database name
must be separated by a single space
/user Specifies 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

/password Specifies the login’s password when using SQL Server authentication
Alias: /p
Format: /password:password
Note: Note: You must use this option together with the /user switch

Create database switches

/db_dir The MDF file of the database created by generated script will be created in the specified directory
Alias: /dbd
Format: /db_dir:D:\ApexSQL
/db_logdir The LDF of the database created by generated script will be created in the specified directory
Alias: /dbld
Format: /db_logdir:log_directory
/db_collation Specifies the database collation
Alias: /dbc
Format: /db_collation:latin_GENERAL_CI_AS
/db_recovery Specifies the recovery mode for the database:

  • simple
  • full
  • bulklogged

Alias: /dbrv
Format: /db_recovery: full
Note: These arguments can’t be combined
Omitting this switch will result in setting “simple” as a default recovery mode

/db_size Specifies the size for the database in KB, MB, or GB
Alias: /dbs
Format: /db_size:1024KB

Specific options switches

/output_type Specifies the output type:

  • tsql – TSQL output format
  • sql – SQL script file
  • script_folder – Scripts folder
  • source_control – Source control
  • csharp – C# project output format
  • exe – .NET executable output format

Alias: /ot
Format: /output_type:[tsql|csharp|exe]
Note: These arguments can’t be combined
Omitting this switch will result in setting a sql as a default output type

/individual Specifies whether object will be written to an individual file.
Script to single file if omitted
Aias: /in
Format: /individual
Note: This argument cannot be used with /cf switch
Omitting this switch will result in scripting to a single file
/create_file Creates separate file for each database
Alias: /cf
Format: /create_file
/folder Specifies the output folder for script each object to an individual file
Alias: /fl
Format: /folder:”D:\ApexSQL\Scripts”
Quick tip icon

Quick tip:

The switch /folder should be used along with the switch /individual

/encoding Specifies the output file encoding:

  • ascii – ASCII encoding
  • unicode – Unicode encoding
  • utf7 – UTF7 encoding
  • utf8 – UTF8 encoding

Alias: /enc
Format: /encoding:[ascii|unicode|utf7| utf8]
Note: These arguments can’t be combined
Omitting this switch will result in setting a unicode as a default encoding

/folder_mapping Creates folder mapping as specified in the previously created folder mapping (XML) file.
Alias: /fm
Format: /folder_mapping:MyMappings.xml
Omitting this switch will result in setting a default mapping
Quick tip icon

Quick tip:

The switch /folder_mapping should be used along with the switch /individual

/project Specifies a project file path
Alias: /pf
Format: /project:project.axsc
Quick tip icon

Quick tip:

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

/mode Specifies the scripting mode:

  • structrure
  • data
  • both

Alias: /m
Format: /mode:data
Note: These arguments can’t be combined
Omitting this switch will result in setting structure as a default scripting mode

/includes Specifies the object selection profile path
Alias: /i
Format: /includes:profile.xml
Omitting this switch will result in including all objects
/include Includes specific objects in the processing. Objects can be specified by
first specifying a bitwise set and a regular expression.
Multiple includes can be specified with spaces in between.
Alias: /inc
Format: /include:bitwise_constant:regular expression
/exclude Excludes specific objects from the processing. Objects can be specified by
first specifying a bitwise set and a regular expression.
Multiple excludes can be specified with spaces in between.
The /exclude switch is processed after the /include switch (if it is specified)
Alias: /exc
Format: /exclude:bitwise_constant:regular expression
/oe:arg [ /output_elements ] A set of the output elements options: None [n] Author [a] DateTime [dt] Legal [l] Comments [cmt] PrintStatements [ps] Default [dft] – Combination of Comments and PrintStatements Note: Arguments can be combined. Author and Legal are paired with /author and /legal switches.

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

Arguments can be combined.

/on:arg [ /output_name ] Output name/folder path of the SQL script, script folder or executable packages (“Script_%date%_%time24%.sql” filename, “Script_folder_%date%_%time12%” folder name, “Package_%date%_%time12%.exe” filename or “Package_%date%_%time24%” folder if omitted)

Owner options switches

/owner_type Specifies the owner mapping type:

  • exclude
  • include
  • change

Alias: /owt
Format: /owt:exclude
Note: These arguments can’t be combined
Omitting this switch will result in setting “include” as an owner mapping type

/owner_map Specifies the owner map
Alias: /owmp
Format: /owmp:”old;new dbo;test”

Main options switches

/no_transaction
_handling
Exclude transaction handling
Alias: /nth
Format: /no_transaction_handling
/no_increment
_version
The version number of the project is not automatically incremented
Alias: /niv
Format: /no_increment_version
/no_scr_use_db Do not script USE database
Alias: /nscu
Format: /no_scr_use_db

Structure script switches

/include_dependent Include dependent database objects
Alias: /sid
Format: /include_dependent
/scr_create_db Script CREATE database
Alias: /scdb
Format: /scr_create_db
/scr_filegroups Script filegroups
Alias: /scf
Format: /scr_filegroups
/scr_logins Script logins with users
Alias: /sck
Format: /scr_logins
/no_scr_names Do not script names
Alias: /scn
Format: /no_scr_names
/scr_collations Script collations. This argument applies only to table objects
Alias: /scc
Format: /scr_collations
/no_scr_ansi_options Do no script ANSI options
Alias: /nsca
Format: /no_scr_ansi_options
/scr_triggers Script triggers with parent table, or view
Alias: /sct
Format: /scr_triggers
/scr_permissions Script database permissions
Alias: /sco
Format: /scr_permissions
/scr_drops Script drops
Alias: /scd
Format: /scr_drops
/scr_ex_properties Script extended properties
Alias: /sce
Format: /scr_ex_properties
/dbcl:arg [ /db_compatibility
_level]
Set script compatibility level for database (“default” if omitted)

  • Default – Default compatibility level
  • SQL2005 – SQL server 2005
  • SQL2008 – SQL server 2008
  • SQL2012 – SQL server 2012
  • SQL2014 – SQL server 2014
  • SQL2016 – SQL server 2016
  • SQL2017 – SQL server 2017
  • Azure – Azure SQL
  • AmazonRDS – Amazon RDS

Arguments cannot be combined.

Data script switches

/no_data_identity_on Do not include SET IDENTITY_INSERT ON in the generated script
Alias: /ndio
Format: /no_data_identity_on
/data_distinct Only distinct rows are scripted. Duplicate rows are discarded
Alias: /ddr
Format: /data_distinct
/data_delete Use DELETE statements
Alias: /dd
Format: /data_delete
/data_rows Set data rows to script:

  • insert_all – script all rows as INSERT
  • insert_update – script all rows as UPDATE and INSERT with existence check
  • insert_new – script new rows as INSERT with existence check

Alias: /drs
Format: /data_rows:insert_new
Note: These arguments can’t be combined
Omitting this switch will result in setting “insert_all” as a default data rows

/data_batch_rows Batch every n rows
Alias: /dbr
Format: /data_batch_rows:10
Omitting this switch will result in setting 1000 rows as default number of rows for batching
/data_apply_date Apply date format
Alias: /dad
Format: /data_apply_date
/data_date_format Set date format
Alias: /ddf
Format: /data_date_format:”YYYYMMDD”
Omitting this switch will result in setting “yyyyMMdd HH:mm:ss” as default date format
/data_trim Set trailing spaces
Alias: /dtt
Format: /data_trim
/ddac
[/data_disable
_constraints]
Disable all triggers and constraints prior to loading data
Alias: /ddac
Format: /no_data_disable_constraints

Script formatting switches

/no_format_comments Exclude comments
Alias: /nfc
Format: /no_format_comments
/format_obj_footer Include object footer
Alias: /fof
Format: /format_obj_footer
/format_obj_header Include object header
Alias: /foh
Format: /format_obj_header
/no_format_prints Exclude PRINT statements
Alias: /nfp
Format: /no_format_prints
/format_scr_footer Include script footer
Alias: /fsf
Format: /format_scr_footer
/no_format_scr_header Exclude script header
Alias: /nfsh
Format: /no_format_scr_header
/obj_footer Object footer template file
Alias: /objf
Format: /obj_footer:object_footer.sql
/obj_header Object header template file
Alias: /objh
Format: /obj_header:object_header.sql
/script_footer Script footer template file
Alias: /scrf
Format: /script_footer:script_footer.sql
/script_header Script header template file
Alias: /scrh
Format: /script_footer:script_header.sql
/adn:arg [
/alter_db_name ]
Alter database name

Script processing

/pre_script Specifies the script to be processed before the generated script is executed
Alias: /pre
Format: /pre_script:argument
/post_script Specifies the script to be processed after the generated script is executed
Alias: /pst
Format: /post_script:argument

Script version switches

/version_major Major version number
Alias: /vmj
Format: /version_major:02
/version_minor Minor version number
Alias: /vmr
Format: /version_minor:005
/version_build Build number
Alias: /vbd
Format: /version_build:0078

Package Options

/package_compression Use package compression
Alias: /pkc
Format: /package_compression
/package_error Specify the package error handling

  • abort
  • ignore
  • ask – ask for confirmation

Alias: /pke
Format: /package_error:[abort|ignore|ask]
Omitting this switch will result in setting “ask” as default package error handling

/package_author Sets the author property for the package
Alias: /pkaa
Format: /package_author:”John Smith”
/package_copyright Sets the copyright property for the package
Alias: /pkar
Format: /package_copyright:”All rights reserved”
/package_legal Sets the legal information property for the package
Alias: /pkal
Format: /package_legal:”This script is protected by copyright law”
/package_comments Sets the comments property for the package
Alias: /pkac
Format: /package_comments:”Comments about this script”
/vsv:arg [
/vs_ver ]
Visual studio version (“2017” if omitted)

  • VS2005 – Visual Studio 2005
  • VS2008 – Visual Studio 2008
  • VS2010 – Visual Studio 2010
  • VS2012 – Visual Studio 2012
  • VS2013 – Visual Studio 2013
  • VS2015 – Visual Studio 2015
  • VS2017 – Visual Studio 2017

Arguments cannot be combined.

/ddb:arg [
/indicate_default
_db ]
Indicate default database
/ren [
/run_exe_now ]
Run executable now
/cmf [
/create_mfs ]
Create manifest file
/cdf [
/create_dat ]
Create dat file
/ccf [
/create_com ]
Create com file
/ovs [ /open_vs ] Open in visual studio

Source control switches

/sourcecontrol_type Specifies the source control:

  • subversion
  • microsoftvisualsourcesafe
  • sourcegearvault
  • teamfoundationserver

Alias: /sctype
Format: /sourcecontrol_type:teamfoundationserver
Note: These arguments can’t be combined

/sourcecontrol_server Specifies the source control server name
Alias: /scsrv
Format: /sourcecontrol_server:server_name
/sourcecontrol_user Specifies the source control login
Alias: /scusr
Format: /sourcecontrol_user:Admin
/sourcecontrol_password Specifies the source control password for login
Alias: /scpwd
Format: /sourcecontrol_password:password
Note: You must use this switch together with the /sourcecontrol_user switch
/sourcecontrol_project Specifies the source control project path
Alias: /scprj
Format: /sourcecontrol_project:project_path
/sourcecontrol_repository Specifies the repository on source control server
Alias: /screp
Format: /sourcecontrol_repository:repository_path
/sourcecontrol_
working_folder
Specifies the path to source control working folder
Alias: /scwfd
Format: /sourcecontrol_working_folder:work_folder_path
/sourcecontrol_label Specifies the label name to be applied to source control project
Alias: /sclbl
Format: /sourcecontrol_label:label_name
/sourcecontrol_comment Specifies the comment for source control operations
Alias: /sccmt
Format: /sourcecontrol_comment:comment

Script tags switches

/tag_author Sets the script author tag
Alias: /sta
Format: /tag_author:”John Smith”

Examples

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

Script each object of database AdventureWorks2014 on LocalServer server into an individual file, and store these files in the “D:\scripts\common” folder:

ApexSQLScript.com /s:LocalServer /d:AdventureWorks2014 /in /fl:”D:\ApexSQL\Scripts”

Set the date format, when scripting the “Table1” table of database AdventureWorks2014 on LocalServer server in the data mode:

ApexSQLScript.com /ddf:”ddMMyyyy HH:mm:ss” /m:data /s:LocalServer /d:AdventureWorks2014 /inc:8:Table1

Script the “Table1” table objects of database AdventureWorks2014 on LocalServer server to .sql file, excluding owners:

ApexSQLScript.com /s:LocalServer /d:AdventureWorks2014 /inc:8:Table1 /owm /owt:exclude

Script database objects 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:

ApexSQLScript.com /pf:”D:\ApexSQL\Projects\AW2014.axsc” /f /v

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

ApexSQLScript.com /argfile:argfile.xml

Include dependent database objects of database AdventureWorks2014 on LocalServer server, when all tables are scripted:

ApexSQLScript.com /sid /s:LocalServer /d:AdventureWorks2014 /inc:8:””

Generate the structure of the objects of database on LocalServer server AdventureWorks2014, specify the .Net executable type of the output file, overwrite an existing file of the same name, and verbose messages that are generated during the script processing:

ApexSQLScript.com /ot:exe /s:LocalServer /d:AdventureWorks2014 /f /v

Script all tables, views and dependent objects in structure mode, of database AdventureWorks2014 on LocalServer server, with login credentials, to the output folder “D:\ApexSQL\Scripts”, using the Folder Mapping file “mappings.xml”, overwrite the existing default output file, and verbose messages that are generated during the script processing:

ApexSQLScript.com /sid /o:12 /s:LocalServer /d: AdventureWorks2014 /u:Username /p:Password /in /fl:”D:\ApexSQL\Scripts” /fm:”D:\ApexSQL\Maps\mappings.xml” /m:structure /v /f