often in books, I see that when a many-to-many relationship is translated into a database schema, JoinTable gets a composite key consisting of the primary keys of tables associated with many many-to-many relationships. I try to completely avoid compound keys. Therefore, I usually create a surrogate key even for JoinTable and let the database fill it with a trigger or any other function that the database has to increase primary keys. This seems like a much simpler approach.
The only problem I can think is that there is a chance of duplicating a pair of foreign keys in JoinTable. But this can be avoided by a simple query before the row is inserted into JoinTable.
Since books always use a composite key approach, I would like to know if there are any negative consequences if I use simple keys for surrogate columns for JoinTable?
source
share