I want to populate automaticaly another table when new data is inserted:

For table “source_table” define a after insert trigger

DELIMITER $$
CREATE TRIGGER `source_table_AINS` AFTER INSERT ON `source_table` FOR EACH ROW
-- Edit trigger body code below this line. Do not edit lines above this one
begin 
insert into dest_table set source_id=NEW.id; 
end

The “NEW” alias contains all inserted fields into table “source_table”;

After “insert” event on table “source_table”, we set the new “id” value into other table “dest_table”;

This is a simple example, it can be used for compute sum, count or similar needs.

Read more about triggers on mysql http://dev.mysql.com/doc/refman/5.0/en/triggers.html

MySQL Trigger – after insert trigger
Tagged on:                         

Leave a Reply

Your email address will not be published. Required fields are marked *