2

I'm fairly new to MySQL. I'm perfectly capable of making queries and creating tables, but never tried triggers before.

CREATE TRIGGER TrigMora AFTER INSERT ON cliente
    REFERENCING NEW AS N
    INSERT INTO mora(Email) VALUES (N.Email);

I'm getting this error:

Error Code: 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 'REFERENCING NEW AS N INSERT INTO mora(Email) VALUES (N.Email)' at line 3

I'm wondering what I'm doing wrong. The idea seemed pretty basic. After a new insertion on table "cliente", the info in the row "Email" should be copied to table "mora".

tshepang
  • 12,111
  • 21
  • 91
  • 136
Peter C
  • 45
  • 1
  • 5

1 Answers1

4

just remove "REFERENCING NEW AS N, and use NEW.Email

you also missing "BEGIN" and "END" surrounding your trigger code

you also miss the "for each row"

check the mysql trigger reference, here i copy u a mysql trigger example:

delimiter //
CREATE TRIGGER upd_check BEFORE UPDATE ON account
    FOR EACH ROW
    BEGIN
        IF NEW.amount < 0 THEN
            SET NEW.amount = 0;
        ELSEIF NEW.amount > 100 THEN
            SET NEW.amount = 100;
        END IF;
    END;//
delimiter ;

copied from: MYsql-reference

Melon
  • 874
  • 8
  • 17
  • you can also check: [mysql after insert trigger which updates another table's column](http://stackoverflow.com/questions/16892070/mysql-after-insert-trigger-which-updates-another-tables-column) – Melon Jan 08 '14 at 11:43