Вопрос

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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top