0

Let's say that I have an articles table that have two columns: title and content, and let's say that this articles table don't have any relationship with any other table.

Why would this articles table have a primary key?

1 Answer 1

0

The purpose of a Primary Key on a table is to ensure uniqueness of the rows in that table by the column(s) defined in the Primary Key. It does not need to be concerned with being part of a relationship with other tables.

Let's say the Primary Key of your example articles table is defined on the title column. This would guarantee that no two rows in the articles table could have the same exact title (because of the unique constraint that a Primary Key enforces).

Additionally, some database systems will automatically cluster the table on the column(s) defined in the Primary Key, typically known as a clustered index. This logically sorts the data by those fields, which can lead to improved query efficiency, especially when filtering or trying to sort the results by that field.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.