简体   繁体   中英

Insert into table with foreign key Mysql

Customer (Customer_id, Customer_Name)

Customer_Phone (Cus_id, Cus_Phone)

I have this two tables and these are connected with a foreign key

I want to insert data to both tables can i do that with one sql statement

The Customer_id in the Customer table is auto Incremented.

This is a one to many relation

i tried INSERT INTO Customer ("Admin","123456")

Please Help thank you

There were two tables, you can insert values to single table at a time. But you can combine multiple inserts in a sql query.

INSERT INTO CUSTOMER VALUES (1,"Customer1"),(2,"Customer2"); INSERT INTO CUSTOMER_PHONE VALUES (1,"133443736466"),(1,"6464747373"),(2,"5664747478");

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