To illustrate how you can resolve date conflicts, suppose a table in a contact management system has a column holding the more recent contact with each customer.
One representative talks with a customer on a Friday, but does not upload his changes to the consolidated database until Monday. Meanwhile, a second representative meets the customer on the Saturday, and updates the changes that evening.
There is no conflict when the Saturday update is replicated to the consolidated database, but when the Monday update arrives, it finds the row already changed.
By default, the Monday update would proceed, leaving the column with the incorrect information that the more recent contact occurred on Friday. However, update conflicts on this column should be resolved by inserting the more recent date in the row.
The following RESOLVE UPDATE trigger chooses the more recent of the two new values and enters it in the database.
CREATE TRIGGER contact_date RESOLVE UPDATE ON Contacts REFERENCING OLD AS old_name NEW AS new_name FOR EACH ROW BEGIN IF new_name.contact_date < old_name.contact_date THEN SET new_name.contact_date = old_name.contact_date END IF END; |
If the value being updated is later than the value that would replace it, the new value is reset to leave the entry unchanged.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |