At my current place of employment someone made a decision to put IDs into a comma delimited column. I'm looking to break these out into a proper many to many relationship. However; it is not in the cards for the application that references this data to change right now. So I need to modify a view to still show the comma delimited column. What is the best way to setup the view so that it displays the comma delimited column? Is there a way to do it that doesn't involve leaving the original column?
A stripped down version of the table definitions is as follows.
ID
ProductName
FeatureIDs
ID ProductName FeatureIDS
1 Hot dog 1,5,4
2 Hamburger 1,3
3 Fish 2
ID
FeatureName
ID FeatureName
1 Mayo
2 TarTar Sauce
3 Pickle
4 Relish
5 Onion
Ultimatly I'd like to combine these into a single products table and a many to many relationship
ID ProductName ProductType
where product type would be either 'product' or 'feature'
ID productid featureid
for the mapping table.
Yes the view that is setup needs to be an updateable view.
SELECTonly or is it the target of data modification statements? – Martin Smith Feb 5 at 14:48XML PATHas per @Aaron's answer you'll also needINSTEAD OFtriggers onINSERTandUPDATEthat split the incoming comma separated values apart then and stores them in the normalised structure (and onDELETEtoo to remove all the associated rows). – Martin Smith Feb 5 at 15:24