SQL Server Data Tools (SSDT) includes a Schema Compare utility that you can use to compare two database definitions. The source and target of the comparison can be any combination of connected database, SQL Server database project, a snapshot, or .dacpac file. The results of the comparison appear as a set of actions that must be taken with the target to make it the same as the source. Once the comparison is complete you can update the target directly (if the target is a project or a database) or generate an update sql script.
Is there a way to automate the process of generating the update script using current (2017) Microsoft technologies?
Note: Automation can either be supported via a .net library or CLI.
1条答案
按热度按时间tvokkenx1#
There are few ways to do that, but the simplest one is to use MSBuild as suggested by @Crowcoder. These are the lines of code that I use in powershell script.
Extract dacpac from database (You might not need that, but if you do then you need sqlpackage for that. Possible location is C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\SqlPackage.exe)
Generate publish script (Possible location is C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe)