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

/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(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
/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’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_dirThe MDF file of the database created by generated script will be created in the specified directory
Alias: /dbd
Format: /db_dir:D:\ApexSQL
/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:latin_GENERAL_CI_AS
/db_recoverySpecifies 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_sizeSpecifies the size for the database in KB, MB, or GB
Alias: /dbs
Format: /db_size:1024KB

Specific options switches

/output_typeSpecifies the output type:

  • tsql – TSQL output format
  • 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 tsql as a default output type

/individualSpecifies 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_fileCreates separate file for each database
Alias: /cf
Format: /create_file
/folderSpecifies 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

/encodingSpecifies 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

/filename_templateSpecifies the filename template
Alias: /ft
Format: /filename_template:”{servername}_{databasename}”
/folder_mappingCreates 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

/projectSpecifies 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

/modeSpecifies 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

/includesSpecifies the object selection profile path
Alias: /i
Format: /includes:profile.xml
Omitting this switch will result in including all objects
/includeIncludes 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
/excludeExcludes 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

Owner options switches

/owner_typeSpecifies 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_mapSpecifies 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_dbDo not script USE database
Alias: /nscu
Format: /no_scr_use_db

Structure script switches

/include_dependentInclude dependent database objects
Alias: /sid
Format: /include_dependent
/scr_create_dbScript CREATE database
Alias: /scdb
Format: /scr_create_db
/scr_filegroupsScript filegroups
Alias: /scf
Format: /scr_filegroups
/scr_loginsScript logins with users
Alias: /sck
Format: /scr_logins
/no_scr_namesDo not script names
Alias: /scn
Format: /no_scr_names
/scr_collationsScript collations. This argument applies only to table objects
Alias: /scc
Format: /scr_collations
/no_scr_ansi_optionsDo no script ANSI options
Alias: /nsca
Format: /no_scr_ansi_options
/scr_triggersScript triggers with parent table, or view
Alias: /sct
Format: /scr_triggers
/scr_permissionsScript database permissions
Alias: /sco
Format: /scr_permissions
/scr_dropsScript drops
Alias: /scd
Format: /scr_drops
/scr_ex_propertiesScript extended properties
Alias: /sce
Format: /scr_ex_properties

Data script switches

/no_data_identity_onDo not include SET IDENTITY_INSERT ON in the generated script
Alias: /ndio
Format: /no_data_identity_on
/data_distinctOnly distinct rows are scripted. Duplicate rows are discarded
Alias: /ddr
Format: /data_distinct
/data_deleteUse DELETE statements
Alias: /dd
Format: /data_delete
/data_rowsSet 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_rowsBatch 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_dateApply date format
Alias: /dad
Format: /data_apply_date
/data_date_formatSet 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_trimSet trailing spaces
Alias: /dtt
Format: /data_trim
/no_data_disable_
constraints
Do not disable all triggers and constraints prior to loading data
Alias: /ddac
Format: /no_data_disable_constraints

Script formatting switches

/no_format_commentsExclude comments
Alias: /nfc
Format: /no_format_comments
/format_obj_footerInclude object footer
Alias: /fof
Format: /format_obj_footer
/format_obj_headerInclude object header
Alias: /foh
Format: /format_obj_header
/no_format_printsExclude PRINT statements
Alias: /nfp
Format: /no_format_prints
/format_scr_footerInclude script footer
Alias: /fsf
Format: /format_scr_footer
/no_format_scr_headerExclude script header
Alias: /nfsh
Format: /no_format_scr_header
/obj_footerObject footer template file
Alias: /objf
Format: /obj_footer:object_footer.sql
/obj_headerObject header template file
Alias: /objh
Format: /obj_header:object_header.sql
/script_footerScript footer template file
Alias: /scrf
Format: /script_footer:script_footer.sql
/script_headerScript header template file
Alias: /scrh
Format: /script_footer:script_header.sql

Script processing

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

Script version switches

/version_majorMajor version number
Alias: /vmj
Format: /version_major:02
/version_minorMinor version number
Alias: /vmr
Format: /version_minor:005
/version_buildBuild number
Alias: /vbd
Format: /version_build:0078

Package Options

/package_compressionUse package compression
Alias: /pkc
Format: /package_compression
/package_errorSpecify 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_authorSets the author property for the package
Alias: /pkaa
Format: /package_author:”John Smith”
/package_copyrightSets the copyright property for the package
Alias: /pkar
Format: /package_copyright:”All rights reserved”
/package_legalSets the legal information property for the package
Alias: /pkal
Format: /package_legal:”This script is protected by copyright law”
/package_commentsSets the comments property for the package
Alias: /pkac
Format: /package_comments:”Comments about this script”

Source control switches

/sourcecontrol_typeSpecifies the source control:

  • subversion
  • microsoftvisualsourcesafe
  • sourcegearvault
  • teamfoundationserver

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

/sourcecontrol_serverSpecifies the source control server name
Alias: /scsrv
Format: /sourcecontrol_server:server_name
/sourcecontrol_userSpecifies the source control login
Alias: /scusr
Format: /sourcecontrol_user:Admin
/sourcecontrol_passwordSpecifies 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_projectSpecifies the source control project path
Alias: /scprj
Format: /sourcecontrol_project:project_path
/sourcecontrol_repositorySpecifies 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_labelSpecifies the label name to be applied to source control project
Alias: /sclbl
Format: /sourcecontrol_label:label_name
/sourcecontrol_commentSpecifies the comment for source control operations
Alias: /sccmt
Format: /sourcecontrol_comment:comment

Script tags switches

/tag_authorSets the script author tag
Alias: /sta
Format: /tag_author:”John Smith”
/tag_companySets the script company tag
Alias: /stc
Format: /tag_company:”ApexSQL LLC”
/tag_legalSets the script legal tag
Alias: /stl
Format: /tag_legal:”All rights reserved”
/tag_custom1Sets the script custom1 tag
Alias: /stc1
Format: /tag_custom1:”Custom1”
/tag_custom2Sets the script custom2 tag
Alias: /stc2
Format: /tag_custom2:”Custom2”
/tag_custom3Sets the script custom3 tag
Alias: /stc3
Format: /tag_custom3:”Custom3”

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