View Single Post

   
  #7 (permalink)  
Old 02-29-2008, 07:50 PM
Roy Harvey
 
Posts: n/a
Default Re: BEGINNER: simple Delete trigger

On Thu, 06 Jul 2006 10:46:50 +0200, R.A.M. <r_ahimsa_m@poczta.onet.pl>
wrote:

>IF EXISTS (SELECT * FROM deleted WHERE Movement IN ('PZ', 'ZW'))
> DELETE FROM PositionsPZZW
> WHERE Number IN (SELECT Number FROM deleted);


That looks dangerous. If one row in DELETED has a 'PZ' value, all
rows in PositionsPZZW that match DELETED will be dropped, even those
that do NOT have 'PZ' or 'ZW'.

How about this alternative:

DELETE FROM PositionsPZZW
WHERE Number IN
(SELECT Number FROM deleted WHERE Movement IN ('PZ', 'ZW'));

It does not require the IF test at all, as if there are no matches it
will do nothing.

Roy Harvey
Beacon Falls, CT
Reply With Quote