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:
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:"AristotleSQL2022" /db1:compare1 /Server2:"AristotleSQL2017" /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.
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.