CHAPTER 8
Data Modification
285
This MERGE statement uses the OUTPUT clause to return the old and new values of the modified
rows. Of course, with INSERT actions, there are no old values, so all references to deleted attributes
return NULL marks. The $action function tells you whether an UPDATE or an INSERT action produced
the output row. Here’s the output of this MERGE statement.
theaction custid oldcompanyname newcompanyname
--------- ------ -------------- --------------
UPDATE 2 cust 2 AAAAA
UPDATE 3 cust 3 cust 3
UPDATE 5 cust 5 BBBBB
INSERT 6 NULL cust 6 (new)
INSERT 7 NULL cust 7 (new)
theaction custid oldphone newphone oldaddress newaddress
--------- ------ -------------- -------------- ---------- ----------
UPDATE 2 (222) 222-2222 (222) 222-2222 address 2 address 2
UPDATE 3 (333) 333-3333 (333) 333-3333 address 3 address 3
UPDATE 5 (555) 555-5555 CCCCC address 5 DDDDD
INSERT 6 NULL (666) 666-6666 NULL address 6
INSERT 7 NULL (777) 777-7777 NULL address 7
(5 row(s) affected)
Do'stlaringiz bilan baham: |