Here is a nice underhand lob pitch to you guys.
So basically I’ve got my content table with unique primary key IDs and I’ve got my tag table with unique primary key IDs.
I’ve got a table that has an identity column as a primary key but the two other columes are the contentID and tagID. What do I need to do to the table to make sure that I only have the same contentID and tagID combo only once.
There’s no reason from a data modeling perspective that you need an identity column in the mapping table. The primary key constraint should be a two-column constraint over
contentID,tagID.Some frameworks (e.g. Rails) demand that every table have a surrogate key named
id, even if it makes no sense for the entity relationship. This is a pity, but apparently this convention gives them some efficiency somewhere else.You can always create a
UNIQUEconstraint overcontentID,tagIDin addition to the table’s primary key on the surrogate key column.