CREATE TRIGGER ... AFTER DELETE ON ... - MySQL

Hi, I am using two tables, lets call them biguser (90+ fields) and smalluser (10 fields). Smaller table is used to speed up search. I am trying to add a trigger that deletes record from smalluser after its deleted in biguser, just like this (id is autoincrement on biguser and non-autoincrement key field on smalluser):

DELIMITER |;
CREATE TRIGGER deluser AFTER DELETE ON biguser
FOR EACH ROW BEGIN
DELETE FROM smalluser WHERE id=OLD.id;
END;
|

And this query always return the following result:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; |' at line 4

MySQL Server is version 5.0.45. After insert trigger worked perfectly.
kichijaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tigin44Commented:

You can not reference the OLD.id column in an AFTER DELETE trigger. Do this deleteion in a BEFORE DELETE trigger.
0
kichijaiAuthor Commented:
Same result for both AFTER DELETE and BEFORE DELETE
0
k_murli_krishnaCommented:
Take a look at example below from:
http://www.digitalpropulsion.org/Programming/Triggers_in_MySQL_5_0

DELIMITER $$

CREATE TRIGGER newsCategoryHandler
AFTER DELETE ON NewsCategories
FOR EACH ROW BEGIN
 DELETE FROM News WHERE catID=OLD.catID;
END;
$$

So, yours should work. There are few reasons for it not to:
1) Your table and column names are wrong.
2) Try a different delimiter like $$
3) See, that there is no loose character anywhere if you are executing from a file
4) It is a compile time error. Check semi-colon should not be there after start or end delimiter like in my example.
0
kichijaiAuthor Commented:
The following query worked:

DELIMITER $$
DROP TRIGGER IF EXISTS `deluser`$$
 
CREATE TRIGGER `deluser` BEFORE DELETE on `biguser`
FOR EACH ROW
BEGIN
DELETE FROM smalluser WHERE id=OLD.id;
END$$
 
DELIMITER ;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tigin44Commented:
you did change the trigger as I mentioned and it worked thats all. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.