简体   繁体   中英

MySQL: Making a joined table auto update when main table is updated

My main table is called users, here I have things like user_id, username etc.

I created a joined table called users_joined who holds some more values that is not in the users table. What users and users_joined has in common is the unique user id for every record in the users table.

Trying to figure out how the users_joined table can be updated automaticly when a new record is insterted into the users table? As for now it only took the values when I ran the query to create the joined table, and if I run a update query.

Can this prosess be automated? If so, what syntax am I looking for?

Triggers will help you to do this, for example :

  CREATE TRIGGER `test1` 
  AFTER INSERT ON `tbl1`
  FOR EACH ROW SET NEW.upd_fld =  new_value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM