I made this trigger:
ALTER TRIGGER "isok" AFTER INSERT
ORDER 1 ON "dba"."orderz"
REFERENCING NEW AS N
FOR EACH STATEMENT
BEGIN
INSERT INTO comments (order_id,user_id,com_content) VALUES (N.order_id,1,'OK');
END
and SQL Anywhere didn’t show an error when I saved it but it does now when I want to insert something into the orderz table:
Correlation name ‘N’ not found
My code is probably wrong but I searched triggers and I have no idea how to fix the problem. All I want to do is to create a new row in the comments table with the new order’s ID in it.
Could someone tell me how to write an expression that would cover it?
You need to replace
with
If you use
STATEMENTthen there is no row to be referenced, because the trigger will fire only once even if you insert ten rows at once.