Hi, I have a table and I want to insert some columns of another table when data is added to this table. Can I do this with MySQL/MariaDB? Or should I use script?
Thanks in advance.
Hi, I have a table and I want to insert some columns of another table when data is added to this table. Can I do this with MySQL/MariaDB? Or should I use script?
Thanks in advance.
Hello @velilinux,
You can do this with SQL standards known as triggers. Here’s an example:
CREATE TRIGGER saveRecord
AFTER INSERT ON mainTable FOR EACH ROW
BEGIN
INSERT INTO secondTable (name, number) VALUES (NEW.name, NEW.number);
END
Unanswered | Unsolved | Solved
MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright © 2006 - 2024 Percona LLC. All rights reserved.