Data rows are identified by the values of primary key columns. Primary key columns must have the same generic non-Other data types. Column name check is case-insensitive, so for example firstName vs FirstName is considered as the same column.
Data row is considered as changed if it has changes in some non-primary-key column and that column has the same generic non-Other data type. If a non-primary-key column has a different generic data type, or one of columns has Other data type, then it is not compared at all.
These rules apply when no database is marked as Target schema. With Target schema, columns are compared by the target data types, see With Target Schema below.
If the table has no compatible primary key (same set of columns with same data types) then data rows are compared just by row number and Data diff tab has an appropriate warning: No comparison key(s). Result can be truncated. Application does not know how to identify whether the row is the same or not, changed or not. Due to the missing key columns the application can not perform paging and has to limit the number of shown rows. Row order in this case is also not guaranteed. Such a data diff result can be used just to get some kind of data changes overview, but it can't be used to identify the number of new and changed rows.
By default the Data diff tab is sorting data by primary keys. You can change sort order. You can also change to sorting column but in this case Data diff may provide unreliable results with invalid changes (both false-positive and false-negative) and shows appropriate warning: Sorting on non-key column(s). To understand why it happens, let's consider the following example: some table with ID primary key, Name column to compare and the following data:
| Left table | Right table | |||
| ID 🔑 ▲ | Name | ID 🔑 ▲ | Name | |
| 1 | Apple | 1 | Green apple | |
| 2 | Banana | 2 | Banana | |
Such a table has row counts Total = 2, New = 0 and Changed = 1 for both sides.
Now if we perform sorting by name then in the right table row with ID=1 will have to be shown last because 'Green apple' > 'Banana':
| Left table | Right table | |||
| ID 🔑 | Name ▲ | ID 🔑 | Name ▲ | |
| 1 | Apple | |||
| 2 | Banana | 2 | Banana | |
| 1 | Green apple | |||
Such a table has row counts Total = 2, New = 1 and Changed = 0 for both sides which is obviously wrong. And visually it may cause an impression that we have more rows than expected.
In the Open databases dialog one of the databases can be marked as Target schema. It is required for the schema merge, and it also changes how data is compared: the data of the other (source) database is compared as it would be stored in the target database.
Only SQL Server DATETIMEOFFSET and Oracle TIMESTAMP WITH TIME ZONE columns store an offset. If both columns store it, two values are equal only if they are the same moment with the same offset. In all other cases the application compares the UTC moments, and a value without an offset counts as UTC. Primary key values are always matched by the UTC moment.
If the target column is a JSON or XML data type (PostgreSQL json, jsonb and xml, MySQL JSON, SQL Server json and xml, Oracle JSON and XMLTYPE), the values are compared without formatting differences. The grid and the merge use the original texts, only the comparison ignores formatting. Text that is not valid JSON or XML is compared as text. A text target column (like TEXT, CLOB or NVARCHAR(MAX)) keeps the exact text, so its values are compared as text.
The application uses the UTC time zone for its MySQL, PostgreSQL and Oracle database sessions, with or without Target schema. So the values of the data types that the database shows in the session time zone are shown and compared in UTC: PostgreSQL timestamptz, MySQL TIMESTAMP and Oracle TIMESTAMP WITH LOCAL TIME ZONE. Data diff shows a warning above the grid of a table with such a column, for example TIMESTAMPTZ values are shown and compared in UTC, not in the local time zone. A merge script value without an offset also means UTC, so a merged value is the same moment as the source value.
These values can be different from what other tools show in your local time zone. Session time functions in Query result diff queries, like now() or CURRENT_DATE, also return UTC values.