In order to version static data, just like database objects e.g. Tables, a mechanism needs to be created to identify only those tables designated as “static” (see below) and to come up with a reproducible process, that will Commit the data in these tables to source control. This article covers this process
Static data is non-transactional data that does not change over time, or even if there are changes, they are not as frequent as for other categories data. Examples of static data include names of cities, zip codes and propriety codes used internally in a company.
ApexSQL Data Diff is a 3rd party tool for comparing and synchronizing SQL database data between various data sources. It compares data between live databases, backups as well as between source control projects/labels and script files. ApexSQL Data Diff natively supports all popular source control systems such as Git, Team Foundation Server, Subversion, Mercurial and Perforce.
For the purpose of this article, we’ll use a Git repository where an existing database schema is already committed. Pubs database will be used as an example. The goal is to commit the static data to the repository so it can be versioned as well.
In order to commit the static data of the Pubs database to source control, the following steps should be performed:
Using the described workflow, static data can be initially committed to the repository.
Let’s create a PowerShell script that contains ApexSQL Data Diff CLI switches in order to automate the process of committing static data. In addition, the script contains data stamped output summary:
$appLocation = ""ApexSQLDataDiff"" | Specifies variable for storing the path to the CLI executable file of ApexSQL Data Diff |
$timeStamp = (Get-Date -Format ""MMddyyyy_HHmmss"") | Specifies variable for storing the time stamp value used in the output file name |
$appCLIcommand = ""/pr:""""Pubs_StaticDataCommit.axdd"""" /sync /v /f /out:""""Output_$timeStamp.txt"""""" | Variable for the CLI command to call the project file and generate the date stamped output file containing the application execution summary |
(Invoke-Expression (""& `"""" + $appLocation +""`"" "" +$appCLICommand)) | Call the specified CLI executable including the additional switches |
""ApexSQL Data Diff return code is $LASTEXITCODE"" >> ""Output_$timeStamp.txt"" | Including the return code in the time stamped summary |
After this is set, save the PowerShell script as CommitStaticData.ps1
In the abovementioned PowerShell script, previously saved project file includes encrypted password for the used Git repository, as well as for the SQL Server connection. In case there is a need to handle credentials in a different way, here are 4 ways of handling database/login credentials during automated execution via the CLI
In order to schedule the saved script, various methods can be used, such as Windows task scheduler, SQL Agent Job, or a PowerShell project. All of these are explained in the Four ways of scheduling ApexSQL tools.
Once the script is executed, it will create the summary containing the return code at the end of the output file:
Changes:
----------------------------------------------------------------------- Name Schema Updated Added Deleted ----------------------------------------------------------------------- pub_info dbo 0 8 0 stores dbo 0 6 0 Total: 0 14 0 ----------------------------------------------------------------------- ApexSQL Data Diff return code is 0
To see a full list of return codes and a description for each one of them, check the Common return error code section part of the General usage and common CLI switches article.
"© 2025 Quest Software Inc. ALL RIGHTS RESERVED. 使用条款 隐私 Cookie Preference Center