To synchronize the schemas of two databases, you can use both standard approaches like Visual Studio and SSDT and third-party tools.
This is how you can do it in Visual Studio:
First of all, Create a SQL Server Database project:
Fig.1 Creating a SQL Server Database project
Then import the database:
Fig.2 Navigating to the database import window
In the window that will be opened, configure the connection to the necessary database and press Start to initiate the import process:
Fig.3 Configuring and starting the database import process
After this, you will be able to see folders, subfolders, and definitions of database objects in the project:
In the same way, you will need to create a project and perform import for the second database.
Now, to compare the database schemas, you just need to right-click any of the two projects and then click Schema Compare… in the context menu:
Fig.5 Navigating to the database schema comparison window
As a result, the database schema comparison window will be opened.
Here you need to select source and target projects and then press Compare to initiate the comparison process:
Fig.6 Database schema comparison window
You can also use other tools to compare database schemas, such as dbForge Schema Compare which integrates with SSMS and is included in the SQL Tools bundle:
Fig.7 Comparing database schemas in SSMS
Here you can configure the source and target for schema comparison:
Fig.8 Configuring the source and target for schema comparison
Table mapping can be configured in the corresponding tab:
Fig.9 Selecting a table for mapping
Fig.10 Configuring field mapping in the table
“Columns details” displays column definition information from two tables: source database on the left and target database on the right.
This is particularly useful when column names are different in the source and the target.
After schemas are compared, you can select the necessary table and see the table definition differences in two databases:
Fig.11 Table schema comparison between two databases
At the bottom left, the definition code of the source database table is displayed, and that of the target database is displayed at the bottom right.
If needed, a synchronization script for any schema table can be generated.
Top comments (0)