|
ApexSQL Knowledgebase Tips and How-to Articles for Apex SQL Tools Mapping in ApexSQL Diff, Part 2: Tables DESCRIPTION This is the second installment in the three-article KB series discussing ApexSQL Diff's mapping ability. With ApexSQL Diff, you can map users/schemas, tables, and columns. Here, we discuss how to map tables. What does "mapping tables" mean? As mentioned in Mapping Schemas, ApexSQL Diff runs in two different modes: Structure mode compares and syncs database structures and Data mode compares and syncs data. Mapping tables applies only to Data mode. By default, ApexSQL Diff automatically maps objects of the same object type and object name and have the same schema. That is, when you have a schema "DBO" in both the source and destination of your project, and both own the tables named "MyTable", these tables will automatically be mapped by ApexSQL Diff. However, when the schemas in both source and destination differ in their names, mapping is not automatic. This is the case even when the object names in the schemas are all equal; the tables will still be unmapped. To address this, ApexSQL Diff allows mapping tables manually. Mapping tables To reproduce the situation, let's issue the following batch: USE MASTER CREATE DATABASE BOSTON GO USE BOSTON GO CREATE SCHEMA BOSTON_USERS AUTHORIZATION DBO GO SELECT * INTO BOSTON_USERS.EMPLOYEES FROM NORTHWIND.DBO.EMPLOYEES The above batch will create a new database named Boston and then switch the database context from master to this new database. Within the Boston database, we create the schema Boston_Users and then copy the structure of the Northwind.dbo.Employees table to the new Boston_Users.Employees table. We now have two tables with identical names and identical data. The important difference is, they are contained in different schemas. We now switch to ApexSQL Diff and create a new data comparison project. As source for the comparison, we choose the Northwind database. For the destination database, we use the Boston database. In the Data Comparison Wizard, we go to the Mapping Tables page where we can select the tables to be matched. The screen will look like the one below: ![]() The grid above the red rectangle is empty because ApexSQL Diff cannot automatically map the Employees table. Although the object types and names are identical, their containing schemas differ. The table pair (dbo.Employees/Boston_Users.Employees) is yet unmapped, and therefore is found in the "Unmapped objects" grid: ![]() Below, the two Employees tables are presented on two different rows: ![]() To map the two Employees tables, place the cursor in the Name column on either row where the Employees table is displayed: ![]() Expand the dropdown list: ![]() Notice the red arrow above. This simply shows that the Unmapped Objects grid is a two-way grid. Meaning, you can achieve the same result when you click either on the dropdown box in Name column in the "Destination half" or the Name column of the "Source half" of the Unmapped Objects grid. ![]() To map two tables permanently in this project, click the "Map" button: ![]() Alternatively you can use the "Map" command from the context menu of the Unmapped Objects grid: ![]() The table pair is immediately moved from the Unmapped Objects grid to the Mapped Objects grid. ![]() You have successfully established a "permanent link" between two tables residing in different schemas. The table dbo.Employees and the table Boston_Users have the same set of columns. What if they were different? This is what we will discuss in the third and last installment. SEE ALSO Mapping in ApexSQL Diff, Part 1: Schemas Mapping in ApexSQL Diff, Part 3: Columns AUTHOR Frank Kirkland LAST REVIEW DATE 31 August 2007 Labels: Apex SQL Diff |
© 2008 Apex SQL Tools All Rights Reserved | 1.919.968.8444 | Contact Us | Terms of Use









