0

I'm trying to, once a table is updated with some new information from an insert, update at the same time another specific column(s) of other table(s) on the same database.

Is like, ok, I save in table1 my age, my country and my name and I have to save at the same time my age in table2, field age2 and my name in table3, field name2. Something like that. But doing it automatically.

I read about the triggers but also read that with triggers you CAN'T specify the name of the table.

Can anyone please help me? I'm pretty lost.

Filburt
  • 17,626
  • 12
  • 64
  • 115
Zariweya
  • 295
  • 3
  • 13
  • 1
    What you mean `CAN'T specify the name of the table` – underscore Apr 26 '14 at 11:27
  • maybe this can give you a point where to start http://stackoverflow.com/questions/16892070/mysql-after-insert-trigger-which-updates-another-tables-column – Angelo Immediata Apr 26 '14 at 11:29
  • I mean I can't "say" to the trigger: INSERT COMING in table1? Ok, insert then in table2. – Zariweya Apr 26 '14 at 11:29
  • @AngeloImmediata, ty, I'm trying that. – Zariweya Apr 26 '14 at 11:34
  • What do you mean with "new register"? There are no "registers" in a relational database. –  Apr 26 '14 at 11:40
  • @a_horse_with_no_name I mean the next. I have 3 tables: items (id, cat_id, user_id, name, description, price), fields_values (id, field_id, item_id, value) and products (id, cat_id, title, description, file). So I want to, once 'items' is updated with new data, automatically insert items.name into products.title. And once 'fields_values' is updated with new data, automatically insert fields_values.value into products.file, for example. – Zariweya Apr 26 '14 at 11:50

1 Answers1

0

You definitely can and must specify the name of the table when creating a trigger! Triggers are defined for data modifications on tables. You should use

CREATE TRIGGER `copy_on_new_data` AFTER INSERT ON `your_table_name` FOR EACH ROW BEGIN [...] END;

and insert the desired data to your other tables using the new qualifier, like

INSERT INTO `other_table`(name) values (new.name);

rekaszeru
  • 19,130
  • 7
  • 59
  • 73