Chapter 7. SQL Remote Design for Adaptive Server Anywhere

 

 

 

that this subquery can be multi-valued.

Multiple-valued

The subquery in the BEFORE INSERT trigger is a UNION expression, and

subqueries

can be multi-valued:

 

...

 

SELECT rep_key

 

FROM Policy

 

WHERE cust_key = NewRow.cust_key

 

UNION ALL

 

SELECT NewRow.rep_key

 

...

 

The second part of the UNION is the rep_key value for the new sales

 

representative dealing with the customer, taken from the INSERT

 

statement.

 

The first part of the UNION is the set of existing sales representatives

 

dealing with the customer, taken from the Policy table.

 

This illustrates the point that the result set of the subscription query must

 

be all those sales representatives receiving the row, not just the new sales

 

representatives.

 

The subquery in the BEFORE DELETE trigger is multi-valued:

 

...

 

SELECT rep_key

 

FROM Policy

 

WHERE cust_key = OldRow.cust_key

 

AND rep_key <> OldRow.rep_key

 

...

 

The subquery takes rep_key values from the Policy table. The values

 

include the primary key values of all those sales reps who deal with the

 

customer being transferred (WHERE cust_key = OldRow.cust_key),

 

with the exception of the one being deleted (AND rep_key <>

 

OldRow.rep_key).

 

This again emphasizes that the result set of the subscription query must

 

be all those values matched by sales representatives receiving the row

 

following the DELETE.

Notes

Data in the Customer table is not identified with an individual subscriber

 

(by a primary key value, for example) and is shared among more than one

 

subscriber. This allows the possibility of the data being updated in more

 

than one remote site between replication messages, which could lead to

 

replication conflicts. You can address this issue either by permissions

 

(allowing only certain users the right to update the Customer table, for

 

example) or by adding RESOLVE UPDATE triggers to the database to

 

handle the conflicts programmatically.

117

Page 135
Image 135
Sybase DC38133-01-0902-01 manual That this subquery can be multi-valued, Can be multi-valued, Following the Delete, 117