r/DatabaseHelp • • Nov 12 '16
Do association/junction tables need a primary key?
For example, if we have a many-to-many relationship between a Book and Author table, does the resulting association table need a primary key? If so, should the primary key be a combination of the resulting foreign key values or an auto-incremented number?
1
Upvotes
3
u/wolf2600 Nov 13 '16
For an association table the PK should be the FK columns.
1
u/BinaryRockStar Nov 13 '16
Yes, all tables should have a primary key.
Yes. If nothing else this will ensure that the combination of the columns is unique, and the table will be ordered by these columns so lookups will be as fast as possible.