DEV Community

Discussion on: Is Primary Key necessary in a table (DBMS)

Collapse
 
peledzohar profile image
Zohar Peled

An index doesn't have to be tied to a primary key, however I would advise to use a composite primary key on the tables you've mentioned.

Thread Thread
 
dmfay profile image
Dian Fay

Adding to this, the ordering of columns in the composite key is important: if movies_directors has a primary key (movie_id, director_id), searching by a movie_id will scan the primary key index, but searching by a director_id has to perform a sequential scan of the table unless there's a secondary index on that column.