Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger problem

Status
Not open for further replies.

mrkan

Programmer
Oct 30, 2006
39
US

I am trying to test/learn how to use triggers.
on mySql 5.0 (Server version: 5.0.37-log)

If I do this:

Code:
CREATE TABLE t (column1 TINYINT);
CREATE TABLE t_test (column2 TINYINT);
CREATE TRIGGER trigger_test
AFTER INSERT ON t
FOR EACH ROW BEGIN
   INSERT INTO t_test (column2) VALUES ('6');
END;

Every time I get error message:

#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 'INSERT INTO t_test (column2) VALUES (6)' at line 4


I can't see what I am doing wrong here? Could this be a privilege problem?
 
to create your trigger, you need to set a different delimiter to encompass the whole statement:

Code:
DELIMITER $$
CREATE TRIGGER trigger_test
AFTER INSERT ON t
FOR EACH ROW BEGIN
   INSERT INTO t_test (column2) VALUES ('6');
END;

$$
// at tyhis point you should see "Query OK, 0 rows affected (0.00 sec)" instead of ERROR......
DELIMITER ;

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top