Data Compare uses Delete/Insert where Update should suffice
David Lee
Posts: 6
Hello,
Using SQL Data compare 6.0 I have just compared a single table on two different servers. 1 row was identified as only appearing in the left DB and 1 row was identified as only appearing in the right DB. On closer inspection the two rows had only a single change in a non-indexed, non-primary key column.
My understanding is that the comparison is performed using the Primary Key as the default (I have checked and that is true in this case).
My query is this: Why did it determine that a DELETE/INSERT pair rather than a single UPDATE statement should be used? What other criteria is used besides the PK?
I hope that this is just my lack of understanding as this nearly caused a catastrophic issue for us as there is a cascade delete relationship on this table that would not be triggered had an UPDATE statement been used.
Thanks
David
Carlson Marketing, Northampton
Using SQL Data compare 6.0 I have just compared a single table on two different servers. 1 row was identified as only appearing in the left DB and 1 row was identified as only appearing in the right DB. On closer inspection the two rows had only a single change in a non-indexed, non-primary key column.
My understanding is that the comparison is performed using the Primary Key as the default (I have checked and that is true in this case).
My query is this: Why did it determine that a DELETE/INSERT pair rather than a single UPDATE statement should be used? What other criteria is used besides the PK?
I hope that this is just my lack of understanding as this nearly caused a catastrophic issue for us as there is a cascade delete relationship on this table that would not be triggered had an UPDATE statement been used.
Thanks
David
Carlson Marketing, Northampton
Comments
I'm pretty sure those are the only situations where it will use DELETE/INSERT rather than UPDATE.
HTH
Project Manager
Red Gate Software Ltd
I am using the GUI and there is no warning that the index is not unique and there are no identity columns in this table. In fact, it is defined as a CLUSTERED UNIQUE primary key and there are no other indices!
On a test environment I have applied the changes and then reran the comparison and now I have this one row appearing as only in left DB and only in right DB, yet the contents of the rows is the same!
Any ideas?
thanks
David
If it's not a string then the order in which the rows are being return from each database may differ - in which case I'd be really curious as to why.
Project Manager
Red Gate Software Ltd
Char( 10 )
Char( 10 )
Varchar( 10 )
Varchar( 10 )
Varchar( 8 )
and the collation is SQL_Latin1_General_CP1_CI_AS across the board.
I will retry the compare with binary collation.
The key is entirely in Capitals. Why should the case-sensitive comparison identify the two rows as the same whereas the case-insensitive comparison says they're different?
:?
David
Sometimes we can get the order wrong in rare cases which is why we've got that lovely option.
I'd be interested to know what the strings are around that area to know the exact problem in our collation implementation as we should be solid and the common collation your using.
Project Manager
Red Gate Software Ltd
I can send you the table in question directly for analysis purposes but I can't post it on a public site. So if we can arrange it privately I can send it to you.
However, looking at the options again I also tried the compare using the trim trailing spaces option and this had the same effect has the collation option. That is, with the option selected the rows appear as different! I have reviewed data and the two rows in question are identical, including the number of spaces.
I'm not getting any less confused with this! :? :?
David
The trim-trailing spaces option is considerably quicker for comparisons than forcing binary collation so I'd stick with that option if it works for you. This is because SQL Server can still use the index when retrieving the data.
If you can send me a copy of the two tables in your servers so I can check that this is the issue and we'll put a test case in and fix it in a future version.
Thanks for all your help on this.
Project Manager
Red Gate Software Ltd