Author Topic: Problem with Trigger Query........  (Read 278 times)

0 Members and 1 Guest are viewing this topic.

Offline man12_patil3Topic starter

  • Irregular
  • Posts: 26
    • View Profile
Problem with Trigger Query........
« on: March 03, 2010, 06:13:06 AM »
 :shrug:


CREATE TRIGGER ins_trig AFTER INSERT ON test
FOR EACH ROW
BEGIN
INSERT INTO test2 (id,  Name,  address,  ph ) (SELECT * FROM `test` ORDER BY id desc LIMIT 0 , 1);
END;

this is my query  when i try it show the following 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 "
on MySQL client version: 5.0.45


please help me

thanks in Advance.....


Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: Problem with Trigger Query........
« Reply #1 on: March 03, 2010, 07:58:37 AM »
Code: [Select]
DELIMITER $$
CREATE TRIGGER ins_trig AFTER INSERT ON test
FOR EACH ROW
BEGIN
INSERT INTO test2 (id,  Name,  address,  ph ) (SELECT * FROM `test` ORDER BY id desc LIMIT 0 , 1);
END$$

DELIMITER ;

BTW: why not
Code: [Select]
INSERT INTO test2 (id,  Name,  address,  ph ) VALUES (NEW.id, NEW.Name, NEW.address, NEW.ph);
« Last Edit: March 03, 2010, 08:00:10 AM by Mchl »
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading