MySQL Forums
Forum List  »  Triggers

Want to create trigger on mysql 5.0.45 with IF NOT EXISTS
Posted by: Prashesh Kachhia
Date: September 22, 2012 05:39AM

I have tried to create trigger on mysql 5.0.45 but it will give error.Same trigger I have successfully created on mysql 5.1.61.

My requirement is, I have two databases and I want to insert into one database table after insert of other database table and also vice a verse.

My trigger is

DELIMITER $$
CREATE DEFINER=root@localhost TRIGGER trigeer_with_if AFTER insert ON `test_new`.employees
FOR EACH ROW
Begin
	If NOT EXISTS(SELECT employeeNumber FROM `test_db`. employees WHERE employeeNumber = NEW.employeeNumber) THEN
	INSERT INTO `test_db`. employees VALUES (NEW.employeeNumber,NEW.lastName,NEW.firstName,substr(NEW.extension,0,LENGTH(NEW.extension)-2),NEW.email,NEW.officeCode,NEW.reportsTo,NEW.jobTitle);
	end if;

END$$
DELIMITER ;

But I have tried to create this trigger though phpmyadmin on mysql 5.0.45 it will gives me below error:

#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 'DELIMITER $$
CREATE DEFINER=root@localhost TRIGGER trigeer_with_if AFTER insert' at line 1

I am new to trigger, so don't know how to resolve this problem.

Thanks,
Pkachhia



Edited 1 time(s). Last edit at 09/22/2012 05:42AM by Prashesh Kachhia.

Options: ReplyQuote


Subject
Views
Written By
Posted
Want to create trigger on mysql 5.0.45 with IF NOT EXISTS
5593
September 22, 2012 05:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.