Mysql insert into 2 tables

后端 未结 4 495
予麋鹿
予麋鹿 2020-11-27 08:00

I want to make a insert into 2 tables

visits:

visit_id int | card_id int

registration:

registration_id int | type          


        
4条回答
  •  感动是毒
    2020-11-27 08:41

    It's not possible with one query as INSERT can only insert data to one table in mysql. You can either

    1. write this as two queries and execute them as a batch
    2. create a stored procedure that would execute two insert command

    You can wrap those inserts in transaction if you need to make sure that both queries will write the data.

提交回复
热议问题