简体   繁体   中英

MySQL AUTO_INCREMENT 2 tables

I have a simple question, I google'd it but my english isn't that good so.

I have 2 tables with both the structure row ID

both are auto_increment but I want them to be in sync so basically both always have to have the same ID number is that possible?

Yes it is possible but it would be better to have one column that is connected to the other table ID

table1:

ID

table2:

ID
table1_id

you can use that auto increment field as primary key in one table. and refer the same field as foreign key in another table.

but auto increment depends on how you are going to insert records in both table.

Table1 :  
ID  -primary key

Table2 :
tablei-id  -foriegn key

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