2

我一直在尝试在 mysql 中设置触发器,但无济于事。以下是与之相关的表格:

mysql> describe ttloki;
+-------------+-----------+------+-----+-------------------+-----------------------------+
| Field       | Type      | Null | Key | Default           | Extra                       |
+-------------+-----------+------+-----+-------------------+-----------------------------+
| Lokinumero  | int(11)   | NO   | PRI | NULL              | auto_increment              |
| Ttnumero    | int(11)   | NO   | MUL | NULL              |                             |
| Kirjausaika | timestamp | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+-----------+------+-----+-------------------+-----------------------------+
3 rows in set (0.00 sec)

mysql> describe tyontekija;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| Numero   | int(11)     | NO   | PRI | NULL    |       |
| Sukunimi | varchar(40) | NO   |     | NULL    |       |
| Etunimi  | varchar(40) | NO   |     | NULL    |       |
| Osasto   | int(11)     | YES  | MUL | NULL    |       |
| Lahios   | varchar(40) | YES  |     | NULL    |       |
| Postino  | varchar(5)  | NO   | MUL | NULL    |       |
| Puhelin  | varchar(16) | YES  |     | NULL    |       |
| Palkka   | int(11)     | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

我最后一次试用触发器是这样的:

create trigger uusitt
after insert on TYONTEKIJA
for each row
insert into TTLOKI(Ttnumero) values
(old.TYONTEKIJA.Numero);

每当我尝试插入 TYONTEKIJA 时,它都会给我关于触发器中值的任何错误。

mysql> insert into TYONTEKIJA(Numero,Sukunimi,Etunimi,Osasto,Lahios,Postino,Puhelin,Palkka) values
    -> (220000, "Saarikoski", "Pekka", 5, "Umpikuja 1", "02760", "060-7358461", 3000);
ERROR 1054 (42S22): Unknown column 'old.TYONTEKIJA.Numero' in 'field list'

我不明白如何正确设置这种触发器。我应该改变什么来解决这个问题?

4

1 回答 1

0

插入值时,不能使用old标识符,因为还没有旧值。也许你的意思是,new.Numero

于 2012-10-03T07:14:29.647 回答