0

The objective is to auto-create a new record in Table 2 when a new record is created in Table 1.

Table 1 has many fields. One is USER_ID. This USER_ID value will be used for the Table 2 USER_ID field. Table 2 has 3 fields(F1 is USER_ID to pull from USER_ID in Table 1). F2 and F3 is a default value set in the table structure.

Thank you for answering my query.

  • You might use triggers for that https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html – tamerlaha May 28 '21 at 19:53
  • 1
    Thank you for all the reply. I used this simple TRIGGER on the user table. CREATE TRIGGER `after_users_insert_auto_user_role` AFTER INSERT ON `users` FOR EACH ROW BEGIN IF NEW.id IS NOT NULL THEN INSERT INTO user_role(user_id) VALUES(new.id); END IF; END – ttwaros Jun 01 '21 at 03:29

0 Answers0