How to use foreign key to create a record in another table

2
I have two tables users and users_info , I would like to use foreign key, so when I create a record in the users table, create a record with the empty fields in the users_info table, only with the id_user completed, is it possible?

    
asked by anonymous 04.09.2017 / 14:26

1 answer

3

I think it would look like this, remember that the fields of the user_info table should allow null values.

CREATE TRIGGER tg_user
AFTER INSERT ON users
FOR EACH ROW
  INSERT INTO user_info (id_user, outro_campo, exemplo)
  SELECT NEW.id, NULL, NULL
  FROM users
  WHERE id = NEW.id
    
04.09.2017 / 14:55