| | |
Trigger problem...
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 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!! :-)
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!! :-)
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
Should you write AS after table name like
MySQL Syntax (Toggle Plain Text)
CREATE TRIGGER trigger_name AFTER INSERT ON table_1 AS ....
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Router/Warcraft III/CS 1.6 problem (Networking Hardware Configuration)
- problem with trigger (MS SQL)
- Toshiba laptop with fractal pink areas on LCD (Monitors, Displays and Video Cards)
- nvidia geforce 5600 graphics problem (Monitors, Displays and Video Cards)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Random screen saver problem is killing me (OS X)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Connection Problems (Networking Hardware Configuration)
Other Threads in the MySQL Forum
- Previous Thread: Help with birthday MySQL Script
- Next Thread: What program for database
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






