•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 456,519 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,821 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 818 | Replies: 1 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Rep Power: 0
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
CREATE TRIGGER trigger_name AFTER INSERT ON table_1 AS ....
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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 / 2003)
- Random screen saver problem is killing me (OS X)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Connection Problems (Networking Hardware Configuration)
- Problem with Windows Update and WinXP (Web Browsers)
Other Threads in the MySQL Forum
- Previous Thread: Help with birthday MySQL Script
- Next Thread: What program for database


Linear Mode