Benefits of using the Row filter in SQL database comparison

Applies to
ApexSQL Data Diff

Summary
This article explains benefits of using the Row filter in SQL database comparison.

Description
If there is a need to compare a predefined range of data in two SQL tables located in different databases and on different servers, but these tables have more than 100 million records, a full table comparison would be too time-consuming and could deteriorate the network and server performance.

In order to avoid any potential issues, boost the comparison performance, and shorten the time required to complete the process, the ApexSQL Data Diff’s Row filter feature can be used to compare just the defined range of data.

To set up the Row filter condition, set up the data sources in the New project window, expand the Advanced options tab and click the Object filter tab:

In the Object filter grid, select the desired table and in the Columns column, click the arrow button to open a drop-down menu, to check out the columns used for the comparison process for a selected table:

In the following example, the Customers table will be filtered by the CustomerID column. To set up the row filter condition, navigate to the Row filter column of the selected table, and then click the three dots button:

The Row filter for the Customer table dialog will be shown where a condition needs to be entered that will fulfill the comparison requirements. For example:

CustomerID >=1000 and CustomerID <=20000

In this example, the condition filters the customers with IDs from 1000 up to 20000.

Below the field where the condition has been entered, the current Row count is shown. Currently, it is 19820:

When the Refresh button in the bottom-right corner is clicked, the Row count number will show the number of rows according to the entered condition. In this example, it is 9001:

If needed, several columns can be used in a single condition applying AND and OR operators, like in the standard T-SQL.

This condition is what ApexSQL Data Diff will inject as the WHERE condition, while selecting from the database. So everything that can be used in the WHERE clause of a T-SQL query, can be used here as well.

The outcome of this filtering is that the number of rows is reduced from 19820 to 9001, which will speed up the comparison and only rows specified by the condition will be compared and synchronized. If the Row filter feature can/needs to be applied to other tables as well, this will provide a significant boost in the comparison speed.

Q: Can I apply different condition for source and destination table?

A: Yes. Below the Row count is the Use the same filter for both objects option, which can be unchecked when there is a need to specify different conditions for source and destination table. You can read more about it from here.

Q: Can I use a different column as a filter condition, which is not a primary key?

A: Yes. You can use any column for the selected table as a filter condition, but appropriate values in the Filter row window need to be entered for that column.