Question: > desc table1; +-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+----------------+ | id | int(5) | NO |
> desc table1; +-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | var | int(5) | YES | | NULL | | +-------+--------+------+-----+---------+----------------+ 2 rows in set (0.00 sec)
> desc table2 -> ; +-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | var1 | int(5) | YES | | NULL | | | var2 | int(5) | YES | | NULL | | +-------+--------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
> DELIMITER $$ > CREATE TRIGGER total BEFORE INSERT ON table2 FOR EACH ROW BEGIN set NEW.var2 = table1.var * new.var1; END$$ Query OK, 0 rows affected (0.11 sec) > DELIMITER ;
]> INSERT INTO table2 (var1) VALUES('5'); ERROR 1109 (42S02): Unknown table 'table1' in field list
How come I cannot insert. I tried many different things, it still cannot insert.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
