Comments
1 comment
-
Hi Arnost,
That is a very challenging question! From the API, it would be simply a matter of excluding differences only present in database2. Using the command-line utility, it's not so easy because there is no option to simply exclude only objects present in database2 so they are not DROPped.
You can, however, run sqlcompare.exe twice to do this; first to determine the objects that you want to exclude and then again to actually synchronize the databases. This batch file does this by running SQLCompare and using the output to construct an XML command file excluding all objects that exist only in the second database. When objects are only present in db2, the characters << are present in the output and it uses this as a filter to zone in on the missing objects. Afterwards, it runs sqlcompare using the XML file constructed from the first comparison result. You may test this against the databases supplied with SQL Compare, WidgetStaging and WidgetProduction.@echo off REM ====== Enter your server and database names here:======= set Server1=localhost\SQLEXPRESS set Server2=localhost\SQLEXPRESS set Database1=WidgetProduction set Database2=WidgetStaging REM ======= Setting up ================== CD \Program Files\Red Gate\SQL Compare 6 REM delete tmp command file if EXIST command.xml DEL command.xml REM ======= Construct an XML command file =================== echo ^<?xml version="1.0"?^> > command.xml echo ^<commandline^> >> command.xml echo ^<server1^>%Server1%^</server1^> >> command.xml echo ^<server2^>%Server2%^</server2^> >> command.xml echo ^<database1^>%Database1%^</database1^> >> command.xml echo ^<database2^>%Database2%^</database2^> >> command.xml REM output a list of SQL objects missing from DB2 to command.xml for /f "tokens=1-5 delims=\[.\] " %%F in ('sqlcompare /s1:%Server1% /s2:%Server2% /db1:%Database1% /db2:%Database2%') do @if "%%I" EQU "<<" echo ^<exclude^>%%F:\[%%G\].\[%%H\]^</exclude^> >> command.xml REM Omit following line to stop the synchronization! echo ^<sync /^> >> command.xml echo ^</commandline^> >> command.xml REM ======= Run the command file ============= sqlcompare /argfile:command.xml
Add comment
Please sign in to leave a comment.
Arnost K.