944,161 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 1234
  • MySQL RSS
Oct 1st, 2007
0

Trigger problem...

Expand Post »
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!! :-)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Udine13 is offline Offline
1 posts
since Oct 2007
Oct 1st, 2007
0

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

MySQL Syntax (Toggle Plain Text)
  1. CREATE TRIGGER trigger_name
  2. AFTER INSERT ON table_1
  3. AS
  4. ....
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Help with birthday MySQL Script
Next Thread in MySQL Forum Timeline: What program for database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC