Running a Command Line SQL Compare Comparison

Recently a customer was looking to automate some of their SQL Compare checks, but they wanted to do this in a dynamic way, since they needed to do this at scale. Their idea was to not have a SQL Compare project, but build a mapping at the command line.

This post addresses a part of their issue. This will look at how to set up a basic SQL Compare command line.

This is a part of a series of posts on SQL Compare on my blog. You can read other posts I’ve written by clicking the link.

Adding Parameters to SQL Compare.

To build up a comparison from the CLI, let’s start with adding parameters slowly. First, let’s just connect. To do that, I’ll run SQLCompare.exe with a couple parameters. We need server and database parameters.

The command line I’ll use will connect to my local machine (Aristotle) and then two databases: dlm_1_dev and dlm_2_integration. The code I’ll run is:

sqlcompare /Server1:"Aristotle" /db1:dlm_1_dev /Server2:"Aristotle" /db2:dlm_2_integration

This uses the /Server1 and /Server2 parameters, which can be shortcutted to s1 and s2. The structure is a colon and the value. For the database, we can use database1 or db1, and database2 or db2. I’ve shown both the long and short items above.

When I run this, I see results, which scroll off the screen for these two items:

2023-10-19 13_39_43-cmd

If I look at a couple named instances, then I need to add in the instance name inside the quotes with a \ that will designate the appropriate instance. This is my command for named instances:

sqlcompare /Server1:"Aristotle\SQL2022" /db1:compare1 /Server2:"Aristotle\SQL2017" /db2:compare2

As you can see below, this gives me a few differences, with the indicators on the right about in which databases the changes are located.

2023-10-19 14_23_15-cmd

This post shows the basics of working with the command line. I’ll look at more advanced options in future posts.

SQL Compare is a fantastic product for simplifying work and it does so much more than this. Give it a try if you own it or download an evaluation today.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.

4 Responses to Running a Command Line SQL Compare Comparison

  1. Steve – I’ve been considering giving SQL Compare a try but the information on the Red-gate site is limited. When you check the requirements it does specify what Windows OS and .Net build you need but it says nothing about where SQL Compare is installed (i.e. SQLS Server or clients workstation) or if you need SA level access to the SQL Server or if dbo access to each DB is enough. Do you know if SQL Compare can be used by someone who’s DB is in the cloud (not necessarily Azure) and they can connect to their DB’s as a dbo user with SSMS. but they have no SA level access and can’t install anything on the SQL Server itself.

    Thanks

    Like

  2. Pingback: SQL Compare at the Command Line – Curated SQL

Comments are closed.