0

Hi all,

Im trying to create a trigger but keep getting a syntax error. Basically the trigger must be created after a insert on table_1 and update another table's fields with 1 depending on what was inserted into table_1 ( apple, orange, banana, grape )

CREATE TRIGGER trigger_name
AFTER INSERT ON table_1
FOR EACH ROW BEGIN
SET @something = (SELECT name FROM table_1 WHERE id =
NEW.id);
IF @something = 'apple' THEN
(UPDATE table_2 SET field = field + 1);
ELSEIF @something = 'orange' THEN
(UPDATE table_2 SET field = field + 1);
ELSEIF @something = 'banana' THEN
(UPDATE table_2 SET field = field + 1);
ELSEIF @something = 'grape' THEN
(UPDATE table_2 SET field = field + 1);
ENDIF;
END;

ANY help would be greatly appreciated!! :-)

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Ramy Mahrous
0

I am using T-SQL but I don't know if my answer is right or wrong

Should you write AS after table name like

CREATE TRIGGER trigger_name
AFTER INSERT ON table_1
AS
....
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.