简体   繁体   English

MySQL AUTO_INCREMENT 2表

[英]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 我有两个表,两个表都有结构行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? 两者都是auto_increment,但我希望它们保持同步,所以基本上两者总是必须具有相同的ID号是可能的吗?

Yes it is possible but it would be better to have one column that is connected to the other table ID 是的,可以,但是最好将一列连接到另一个表ID

table1: 表格1:

ID

table2: 表2:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM