简体   繁体   English

使用自动增量主键作为外键

[英]Using Autoincrement Primary keys as Foreign Keys

I'm creating a database and I'm not sure about one thing. 我正在创建数据库,但我不确定一件事。 I have an autoincrement primary key which I want to use as a foreign key. 我有一个要自动用作自动外键的主键。 Should the foreign key also be autoincrement? 外键也应该是自动递增的吗?

The foreign key field must not be auto-increment. 外键字段不得为自动递增。 Auto-increment values imply that the field is not a foreign-key. 自动增量值表示该字段不是外键。

The purpose of auto-increment attributes is to generate a unique identity for new rows in the current table . 自动递增属性的目的是为当前表中的新行生成唯一标识。 The purpose of foreign keys is to uniquely identify rows in another table . 外键的目的是唯一标识另一个表中的行。 They are very different things and you should read more about both and properly understand the difference. 它们是完全不同的事物,您应该阅读这两者的更多信息并正确理解它们之间的区别。

自动增量允许在将新记录插入表中时生成唯一编号。

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

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