Assume you have the same data model as described here.
Table: Item
Columns: ItemID, Title, Content
Table: Tag
Columns: TagID, Title
Table: ItemTag
Columns: ItemID, TagID
If you want to have tag synonyms similarly as are on stackoverflow, where would you place this information in the data model? Would you add only one attribute with comma-separated list of synonyms or would you transform a data model a little?
How the SQL statement for inserting new item would look like? Will the new item be connected with all the synonyms or only with one main tag and in the code we have to detect that this is a synonym?
Which approach would you recommend for smooth inserting, deleting and searching by tag operations?
Change the
Tagtable and add aTagSynonymtable:The
TagSynonym.TagIDwould be an FK toTag(TagID)and theTitlewould be the PK.If you also want to have a “MainSynonym” tag, then you could use this:
with
TagMainSynonym(TagID)being the PK andTagMainSynonym(TagID, Title)being an FK toTagSynonym(TagID, Title).It may look overdue but a simple operation like merging two tags will only need a simple
UPDATE(one row) on theTag.TagIDand the cascading effects will do the rest (in 3 tables)