MySQL I have a table with an auto-increment field, which is the primary key:
CREATE TABLE myTable ( id INT AUTO_INCREMENT PRIMARY KEY, field VARCHAR(45) ); In the second field, I want to write the value that should be calculated based on the value of the primary key.
This does not work:
CREATE TRIGGER `myTable_AFTER_INSERT` AFTER INSERT ON `myTable` FOR EACH ROW BEGIN UPDATE myTable SET field=CONCAT(NEW.id,"T") WHERE id=NEW.id; END; When I try to add, I get a MySQL error:
Can't update table "myTable" is in stored function.
And the next option doesn't work either:
CREATE TRIGGER `myTable_BEFORE_INSERT` BEFORE INSERT ON `myTable` FOR EACH ROW BEGIN SET NEW.field=CONCAT(NEW.id,"T"); END; Because in this case NEW.did is not yet defined.
How do I solve the problem? Thank!