Database Schema Synchronization
After opening the studio, go to the âDatabase Syncâ tab and create a new connection by clicking on the âNew Connectionâ button:
In the connection settings window that opens, you must enter the necessary data to connect to the MS SQL Server instance (source server). Please note that in addition to MS SQL Server, Windows, Active Directory authentication, authentication through MFA has appeared. After filling in all the necessary fields, click on the âTest Connectionâ button to test the connection:
After the connection is established, the following dialog box appears:
Next, click on the âOKâ button in the dialog box and the same button in the connection settings window.
Now a new connection has appeared:
Similarly, you need to connect all the necessary instances of MS SQL Server (in this example, you need to create a connection for the destination server).
After that, click on âNew Schema Comparisonâ to configure the process of comparing database schemas on the source server and the database on the destination server:
A settings window for comparing circuits will appear.
On the "Source and Target" tab on the left in the Source panel, you must select:
- type of
- connection
- source database
On the right in the Target panel you need to select:
- type of
- connection
- receiver database
Please note that in the type you can select not only the database, but also the script directory, snapshot, version control and backup. In our case, we select in the "database" type.
After selecting all the settings, you must click on the âNextâ button to continue setting up synchronization of database schemas.
If two initially identical databases are compared, then you can immediately start comparing the schemas by clicking on the âCompareâ button.
If necessary, you can go to any settings tab by clicking on the corresponding item in the left window.
At any stage, you can save the settings as a bat-file by clicking on the âSave Command Lineâ button in the lower left of the window.
In most cases, when rolling changes between initially identical databases, just click on the âCompareâ button. But for functional research it is necessary to click âNextâ:
In the Options tab, you can set various settings or leave them by default:
In the âSchema Mappingâ tab, you can configure the mapping of schemes by name:
In the âTable Mappingâ tab, you can configure the mapping of tables and columns:
In the âObject Filterâ tab, you can specify objects for comparison.
After that, if necessary, you can return to the previous steps.
At the end, you must click on the âCompareâ button to start the process of comparing the schemes of the specified databases:
The database schema comparison settings window will disappear, and a window will appear with an indicator of the comparison process:
At the end of the process, pay attention to the window. You can change the comparison settings by clicking on the âEdit Comparisonâ button in the upper left corner of the window. To the right of this button is a circle with an arrow - this is the update button, which starts the process of comparing schemes again. Also located below are all previously registered servers:
Through the main menu in File, you can save the settings for comparing circuits as a file with the scomp extension.
Now let's pay attention to the central part of the window. Here you need to select the necessary objects for synchronization with checkmarks. On the left are the source objects, and on the right, the receiver. Below in the same way is the code for defining objects. Objects for comparison are divided into 4 sections with a count of the number of these objects in each section.
Here, a table is selected for viewing the definition code, which is both in the source and in the receiver. Therefore, this object is located in the "Different" section:
When you select this object, its definition code on the left will be moved to the right when synchronizing database schemes for the receiver.
Here, to view the definition code, a view is selected that is only in the source. Therefore, this object is located in the âOnly in sourceâ section and there is no definition code for it on the right:
When choosing such an object, its creation code will be generated for the receiver.
Here, to view the definition code, a view is selected that is only in the receiver. Therefore, this object is located in the âOnly in targetâ section and there is no definition code for it on the left:
When choosing such an object, its deletion code will be generated for the receiver.
Next, to start the process of synchronizing database schemas, click on one of the buttons highlighted in red in the picture:
In the âOutputâ tab, you must specify how the synchronization process will occur. Usually the script generation is selected in the studio or in a file. In our case, we will choose the first option. It is recommended that you carefully go through the sequence of all the tabs for setting up the synchronization process:
In the âOptionsâ tab, you can set various settings for synchronizing database schemas.
Usually, all settings from the Database backup group are removed.
By default, in the settings group âTransactionsâ, âUse a single transactionâ and âSet transaction isolation level to SERIALIZABLEâ are set, which prevents situations in which only parts of the changes can be applied - i.e. changes will be applied in full or not at all:
The Summary tab displays the results of the selection of synchronization settings. If necessary, you can return to the previous paragraphs.
Please note that the settings for synchronizing database schemas can also be saved to a bat file by clicking on the âSave Command Lineâ button in the lower left of the window.
At the end, you need to click on the âSynchronizeâ button to start the process of generating a script for synchronizing database schemas:
Upon completion, a script will be generated in a new window:
This script is the code for transferring database schema changes from source to receiver. It can be used on the destination server or saved to a file for later use on the destination server. As a rule, in any case, this script is saved in order to apply it on several servers for the same database after all the checks. This can be done using groups of registered servers in SSMS by sending the resulting script immediately to the entire desired group of servers:
After synchronization, previously selected objects should disappear from the circuit comparison window:
Database Data Sync
It is assumed that the necessary connections have been created as described above in âDatabase Schema Synchronizationâ.
After that, you need to click "New Data Comparison" to configure the process of comparing the database data on the source server and the database on the destination server:
A settings window for comparing data will appear.
On the "Source and Target" tab on the left in the Source panel, you must select:
- type of
- connection
- source database
On the right in the Target panel you need to select:
- type of
- connection
- receiver database
Note that in the type you can select not only the database, but also the script directory and backup. In our case, we select in the "database" type.
After selecting all the settings, click âNextâ to continue setting up the synchronization of database data.
Unlike circuit comparison, when comparing data, it is recommended that you go through all the configuration steps in sequence.
If necessary, you can go to any settings tab by clicking on the corresponding window element on the left.
At any stage, you can save the settings as a bat file by clicking the âSave Command Lineâ in the lower left of the window.
After setting the âSource and Targetâ tab, click âNextâ:
In the Options tab, you can set various settings or leave them by default:
The âMappingâ tab provides a list of tables for data synchronization. Exclamation marks indicate those tables in which there is no primary key. For such tables, matching must be done manually. To do this, select the desired row (table) and on the right click on the ellipsis:
The matching window will appear:
After that, if necessary, you can return to the previous steps.
At the end, click âCompareâ to start the process of comparing the data of the specified databases:
The settings window for comparing database data will disappear and a window will appear with an indicator of the progress of the comparison:
At the end of the process, pay attention to the window. You can change the comparison settings by clicking âEdit Comparisonâ in the upper left corner of the window. To the right of this button is a circle with an arrow - this is an update button that starts the data comparison process again. Also located below are all previously registered servers:
Through the main menu in File, you can save the settings for comparing circuits as a file with the dcomp extension.
Now let's pay attention to the central part of the window. Here you need to select the necessary objects for synchronization with checkmarks. On the left are the source objects, and on the right - the receiver:
The following information is displayed below:
- for inserted rows - data of inserted rows:
- for mutable strings - string comparison:
- for deleted rows - data of deleted rows:
At the bottom left, if necessary, you can select not all the lines for changes, but the ones you need. By default, all rows are selected:
You can also switch between added, changed, and deleted rows using the tabs above the data table itself:
To control the visibility of the desired columns (fields) there is the necessary functionality:
By default, all columns are selected.
Next, to start the database data synchronization process itself, you need to click on one of the buttons highlighted in red in the picture:
In the âOutputâ tab, you must specify how the synchronization process will occur. Usually the script generation is selected in the studio or in a file. In our case, we will choose the first option. It is recommended that you carefully go through the sequence of all the tabs for setting up the synchronization process:
In the Options tab, you can set various settings for synchronization.
Usually, all settings from the Database backup group are removed.
By default, in the settings group âTransactionsâ, âUse a single transactionâ and âSet transaction isolation level to SERIALIZABLEâ are set, which prevents situations in which only parts of the changes can be applied - i.e. changes will be applied in full or not at all:
The Summary tab displays the results of the selection of synchronization settings. If necessary, you can return to the previous paragraphs.
Please note that the settings for synchronizing database schemas can also be saved in a bat file by clicking the "Save Command Line" in the lower left of the window.
At the end, you need to click "Synchronize" to start the process of generating a synchronization script:
Upon completion, a script will be generated in a new window:
This script is the code for transferring data changes from the source to the receiver. It can be applied on the server-receiver or saved to a file for later use on the server-receiver.
After synchronization, previously selected objects should disappear from the data comparison window.
DbForge Compare Bundle for SQL Server at a Glance
In addition to dbForge Studio for SQL Server itself, you can use the dbForge Compare Bungle for SQL Server tool from Devart, which is built into SQL Server Management Studio (SSMS), to compare data and database schemas. Consider an example of using this tool in SSMS:
Here you need to right-click on the desired database and select the desired action: data comparison or circuit comparison. After that, install the selected database as a source or as a receiver. Similarly, select the second database as a receiver or as a source.
After setting the source and receiver, to start the configuration of data synchronization or database schema, click on the green arrow in the middle of the screen:
After that, the familiar window for setting data synchronization or database schemas will appear, depending on what was previously selected.