SQL Compare - 9.0

SQL Compare

Learning SQL Compare - 9.0

Switches used in the command line

This topic provides a list of the switches you can use with the SQL Compare command line.

Note that:

  • the first data source ( /db1, /b1, and so on ) is the source
  • the second data source ( /db2, /b2, and so on ) is the target
  • The command line syntax of previous versions of SQL Compare is considered deprecated, but continues to be supported.

    For example, in SQL Compare 7, the alias for /BackupSet1 was /bs1. In SQL Compare 8, the alias is now /bks1. You can continue to use /bs1 in SQL Compare 8, but a message is displayed informing you of the new alias.

Deprecated command line syntax will cease to be supported at a future release.

/AllowIdenticalDatabases

This switch is deprecated. Instead use /Include:Identical

/Include:Identical suppresses the exit code if the two data sources are identical.

If /Include:Identical is not set, and the data sources are identical, SQL Compare returns the error code 63.

/Argfile:<argfile>

Runs a file containing an XML argument specification:

sqlcompare /Argfile:XMLFileName.xml

For more information see Using XML to specify command line arguments

/Backup1:<filename1>;<filename2>;...;<filenameN>

Alias: /b1

Specifies the backup to be used as the first data source (the source). You must add all of the files making up the backup set you want to compare:

sqlcompare /Backup1:D:\BACKUPS\WidgetStaging.bak /db2:WidgetStaging

To specify more than one backup file, the file names are separated using semicolons:

sqlcompare /Backup1:D:\BACKUPS\WidgetDev_Full.bak;
     D:\BACKUPS\WidgetDev_Diff.bak /db2:WidgetDev

For more information, see Working with backups

/Backup2:<filename1>;<filename2>;...;<filenameN>

Alias: /b2

Specifies the backup to be used as the second data source (the target). You must add all of the files making up the backup set you want to compare:

sqlcompare /db1:WidgetStaging /Backup2:D:\BACKUPS\WidgetStaging.bak

/BackupPasswords1:<Password1>,<Password2>,...,<Password1N>

Alias: /bpsw1

Specifies the password for the first backup:

sqlcompare /Backup1:D:\BACKUPS\WidgetStaging.bak
     /BackupPasswords1:P@ssw0rd /db2:WidgetProduction

/BackupPasswords2:<Password1>,<Password2>,...,<Password1N>

Alias: /bpsw2

Specifies the password for the second backup:

sqlcompare /db1:WidgetStaging
     /Backup2:D:\BACKUPS\WidgetProduction.bak /BackupPassword2:P@ssw0rd

/BackupSet1:<backupSet>

Alias: /bks1

If you are comparing a backup set that contains multiple files, use the /BackupSet1 switch to specify the files which make up the first backup set, and use the /BackupSet2 switches to specify the files which make up the second:

sqlcompare /Backup1:"D:\MSSQL\BACKUP\WidgetDev.bak"
     /BackupSet1:"2008-09-23 Full Backup" /db2:WidgetLive

If the backup set switches are not specified, SQL Compare uses the latest backup set.

To specify more than one backup file, the file names are separated using semicolons.

sqlcompare /Backup1:D:\BACKUPS\WidgetDev_Full.bak;
     "D:\BACKUPS\WidgetDev_Diff.bak" /db2:WidgetDevlopment

For encrypted backups that have been created using SQL Backup, use the /BackupPasswords1 and /BackupPasswords2 switches to specify the passwords; when there is more than one password, the passwords are separated using semicolons.

sqlcompare /Backup1:D:\BACKUPS\WidgetDev.sqb /BackupPassword1:Pa$$w0rd
     /db2:WidgetLive

/BackupSet2:<backupSet>

Alias: /bks2

Specifies which backup set to use for the second backup:

sqlcompare /db1:WidgetProduction /BackupSet2:"2008-09-23 Full Backup"

/Database1:<database1>

Alias: /db1

Specifies a database to use as the source:

sqlcompare /Database1:WidgetStaging /Database2:WidgetProduction

/Database2:<database2>

Alias: /db2

Specifies a database to use as the target.

/Exclude:<object type>:<regular expression>

Arguments:

  • Additional

only those objects that are not present in the source (eg /db1)

  • Missing

only those objects that are not present in the target (eg /db2)

  • Different

only those objects that are present in both data sources, but are different.

  • Identical

identical objects in the command line output and any generated reports.

  • User specified

objects you specify with a regular expression (eg /Include:Table:WidgetPurchases)

To specify the list of objects to exclude, use the /exclude switch:

sqlcompare /db1:Customers1 /db2:Customers2 /Exclude:table

/Exclude:table specifies that you do not want to compare tables; you only want to compare other objects such as views, stored procedures, and so on.

To specify more than one object or object type type for exclusion use multiple /Exclude switches. For example, to exclude only tables and views:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
     /Exclude:table:WidgetReferences /Exclude:view

Note that you cannot use /Exclude with the /Include and /Project switches.

For a more detailed example using the /include and /exclude switches, see Selecting tables with unrelated names

/Filter

Alias: /ftr

Specifies a custom filter to select objects for synchronization.

sqlcompare /db1:WidgetStaging /db2:WidgetProduction /sync

     /Filter:MarketingViewsOnly.scpf

You can set up a filter to include or exclude objects based on their type, name, and owner (schema) name.

This is useful, for example, if you want to create complex selection rules without using regular expressions.

Note that:

  • filters are set up in the graphical user interface
  • filters are saved with the extension .scpf
  • /Filter cannot be used with /Include or /Exclude
  • if you use /Filter with /Project, the filter you specify overrides any filter used in the project

For more information, see Using filters

/Force

Alias: /f

This forces the overwriting of any output files that already exist. If this switch is not used and a file of the same name already exists, the program will exit with the exit code indicating an IO error.

/IgnoreParserErrors

If SQL Compare encounters any high level errors when parsing a scripts folder, it will exit with an error code of 62.

Use /ignoreParserErrors to force SQL Compare to continue without exiting.

/Include:<object type>:<regular expression>

Arguments:

  • Additional

only those objects that are not present in the source (eg /db1)

  • Missing

only those objects that are not present in the target (eg /db2)

  • Different

only those objects that are present in both data sources, but are different.

  • Identical

identical objects in the command line output and any generated reports.

  • User specified

objects you specify with a regular expression (eg /Include:Table:WidgetPurchases)

This switch is used to specify the list of objects to include. You can use an /Include switch for each object that you want to compare. However, this can be unwieldy if there is a long list. Instead, you can use the pipe character ( | ) to separate the table names:

sqlcompare /db1:Customers1 /db2:Customers2 /Include:table
     /Include:table:\[Product\]^|Customer^|Order^|Invoice

For more detailed information on using the /Include switch, see: Selecting tables with unrelated names.

/IncludeIdentical:<IncludeIdentical>

This switch is deprecated. Instead use /Include:Identical

/MakeScripts:<folder>

Alias: /mkscr

Creates a scripts folder from the first (source) data source.

sqlcompare /db1:WidgetStaging
     /MakeScripts:"C:\Scripts Folders\Widget staging scripts"

If the folder already exists an error will occur. To merge scripts into an existing scripts folder, compare them with that folder and use the /synchronize switch:

sqlcompare /scr1:"C:\Scripts Folders\Widget dev scripts"
     /scr2:"C:\Scripts Folders\Widget staging scripts" /Synchronize

For more information, see Working with scripts folders

/MakeSnapshot:<FileName>

Alias: /mksnap

Creates a snapshot from the first (source) data source.

sqlcompare /db1:WidgetStaging
     /MakeSnapshot:"C:\Widget Snapshots\StagingSnapshot.snp"

If the file already exists an error will occur, unless you have also used the /force switch.

/Options:<option1>,<option2>,<option3>

Alias: /o

Applies the project configuration options used during comparison or synchronization:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
     /Options:Default,IgnoreWhiteSpace

For a detailed list of these options see: Options used in the command line.

/Out:<FileName>

Redirects console output to the specified file:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction /Out:C:\output file

/OutputProject:<FileName>

Alias: /outpr

Writes the settings used for the comparison to the specified SQL Compare project file:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
/Options:Default,IgnoreWhiteSpace /OutputProject:"C:\WidgetProject.scp"

This also generates a SQL Compare project file. These files end with a .scp extension. If the file already exists an error will occur, unless you have also used the /force switch.

/OutputWidth:<columns>

Forces the width of console output.

This can be used to ensure that database object names etc are not truncated, and that SQL script lines are not wrapped or broken. This is particularly useful when redirecting output to a file as it allows you to overcome the limitations of the default console width of 80 characters.

/Password1:<password1>

Alias: /p1

The password for the first database (source).

You must also provide a username. If you do not specify a username and password combination, integrated security is used:

sqlcompare /db1:WidgetStaging /UserName1:User1 /Password1:P@ssw0rd
     /db2:WidgetProduction /UserName2:User2 /Password2:Pa$$w0rd

Note that this switch is only used if the source is a database. If the source is a backup, use /BackupPasswords1

/Password2:<password2>

Alias: /p2

The password for the second database (target).

/Project

Alias: /pr

Uses a SQL Compare project (.scp) file for the comparison.

To use a project you have saved as "widgets.scp" from the command line:

sqlcompare /Project:"C:\SQLCompare\Projects\Widgets.scp"

Note that:

  • When you use a project, all objects that were selected for comparison when you saved the project are automatically included.
  • When you use the command line, your project option selections are ignored and the defaults are used. Use /Options to specify any additional options you want to use with a command line project.

    For more information, see Options used in the command line

  • If you want to include or exclude objects from an existing project, you must modify your selection using the graphical user interface.

    You cannot use the /Include and /Exclude switches with /Project.

The /Project switch is useful, for example, as you cannot specify a custom filter in the command line, and specifying complex object selections using a regular expression can be unwieldy.

For more information on using projects, and what a project contains see Working with projects

/Report:<filename>

Alias: /r

Generates a report and writes it to the specified file.

The type of report is defined by the /ReportType switch. If the file already exists an error will occur, unless you have used the /Force switch:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
     /Report:"C:\reports\WidgetReport.html" /ReportType:Simple

/ReportType:<reporttype>

Alias: /rt

Arguments:

  • XML

Simple XML report

  • Simple

Simple HTML report

  • Interactive

Interactive report

  • Excel

Microsoft Excel spreadsheet

This switch defines the file format of the report produced by the /Report switch. The default setting is XML.

For example:

sqlcompare/db1:WidgetStaging /db2:WidgetProduction
     /Report:"C:\reports\WidgetReport.html" /ReportType:Simple

For more information, see Exporting the comparison results

/ScriptEncoding:<scriptencoding>

Alias: /senc

Arguments:

  • UTF8

UTF-8 encoding, without preamble

  • UTF8WithPreamble

UTF-8 encoding, with 3-byte preamble

  • Unicode

UTF-16 encoding

  • ASCII

ASCII encoding

Specifies the character encoding used when writing the SQL script file. The default is UTF8.

For example:

sqlcompare /db1:WidgetStaging /MakeScripts: D:\Scripts Folder
     /SyncScriptEncoding:ASCII

/ScriptFile:<scriptfile>

Alias: /sf

Generates a SQL script to migrate the changes which can be executed at a later time. If the file already exists an error will occur, unless you use the /Force switch:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
     /ScriptFile: "C:\Scripts Folder\WidgetSyncScript.sql"

/Scriptfile can be used when the target ( /db2, /scr2, /sn2 ) is a database, a snapshot, or a scripts folder.

If the target is a snapshot or a scripts folder, the generated script modifies a database with the schema represented by that snapshot or scripts folder.

/Scripts1:<folder>

Alias: /scr1

Specifies the script folder to use as the first data source:

sqlcompare /Scripts1:"C:\Scripts Folder\WidgetStagingScript"
     /db2:WidgetProduction

/Scripts2:<folder>

Alias: /scr2

Specifies the script folder to use as the second data source.

/Server1:<server1>

Alias: /s1

Specifies the server on which the first (/db1:) data source is located. If an explicit path is not specified, it defaults to Local.

sqlcompare /Server1:Widget_Server\SQL2008 /db1:WidgetStaging
     /db2:WidgetProduction

/server2:<server2>

Alias: /s2

This specifies the server on which the second (/db2:) data source is located. If an explicit path is not specified, it defaults to Local.

/snapshot1:<filename>

Alias: /sn1

Specifies the snapshot to use as the first data source:

sqlcompare /Snapshot1:"C:\Snapshots\WidgetStagingSnapshot.snp"
     /db2:WidgetProduction

/snapshot2:<filename>

Alias: /sn2

Specifies the snapshot to use as the second data source:

/Synchronize or /Synchronise

Alias: /sync

Synchronizes the databases after comparison.

The target (for example, /db2) is modified; the source (for example, /db2) is not modified:

sqlcompare /db1:WidgetStaging /db2:WidgetProduction
     /Synchronize

/UserName1:<username1>

Alias: /u1

The username for the first database.

If no username is specified, integrated security is used.

sqlcompare /db1:WidgetStaging /UserName1:User1 /Password1:P@ssw0rd
     /db2:WidgetProduction /UserName2:User2 /Password2:Pa$$w0rd

/UserName2:<username2>

Alias: /u2

The username for the second database.

If no username is specified, integrated security is used.

See also

Options used in the command line

Exit codes used in the command line

Was this article helpful?

Search support
Forums
Visit the SQL Compare forum.

SQL Compare

all SQL products

all products