Monitor table then insert to another table

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
1 Like