![]() |
| ||
| Trigger problem... 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!! :-) |
| ||
| Re: Trigger problem... 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 |
| All times are GMT -4. The time now is 3:32 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC