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

时间:2022-07-16 11:29:52

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?

我正在创建一个数据库,我不确定有什么。我有一个自动递增主键,我想把它用作外键。外键也应该是自动递增的吗?

2 个解决方案

#1


3  

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.

自动递增属性的目的是为当前表中的新行生成唯一标识。外键的目的是惟一地标识另一个表中的行。它们是非常不同的东西,你应该更多地了解这两者,并正确地理解它们的区别。

#2


-1  

Auto-increment allows a unique number to be generated when a new record is inserted into a table.

自动增量允许在将新记录插入到表中时生成唯一的数字。

#1


3  

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.

自动递增属性的目的是为当前表中的新行生成唯一标识。外键的目的是惟一地标识另一个表中的行。它们是非常不同的东西,你应该更多地了解这两者,并正确地理解它们的区别。

#2


-1  

Auto-increment allows a unique number to be generated when a new record is inserted into a table.

自动增量允许在将新记录插入到表中时生成唯一的数字。