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: 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: 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:
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: 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: 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: If a project file is saved outside of the installation directory, specify the path where it’s located |
/mode | Specifies the scripting mode:
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:
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
|