DB2 EXISTS TRIGGER
I use DB2 and writing a trigger count version works but I can't convert it to exists version. I will use exists version because of performance reasons. It is a insert after trigger.
it works
IF (SELECT COUNT(*) FROM table where field=NEW.field ) = 0 THEN
---------
END IF;--
it doesn't work
IF NOT EXISTS (SELECT * FROM table 开发者_运维问答where field=NEW.field ) THEN
---------------------
END IF;--
TRY THIS: ,AS
BEGIN ATOMIC IF NOT EXISTS (SELECT * FROM table where field=NEW.field) THEN INSERT INTO ABC.table1 ("field1") VALUES (1100200); --> HERE IS A DUMMY INSERT I USED TO EXPLAIN END IF; END;
this syntax to run this code
db2 -td@ -f mysql.db2
You need to tell DB2 about the terminator you used !!
AND
--#SET TERMINATOR $ This will ser the terminator to $ To change the terminator in the CLP on the fly, the following syntax will set it back: --#SET TERMINATOR
精彩评论