I have the following table:
SubjectID AttributeID ValueID
1 1 2
1 1 3
1 2 1
2 1 3
2 2 1
1 3 1
An attribute can have multiple values (multiple appearances in the above table for the same attribute). There is no constraint of how many appearances for the same attribute (different value).
I wan't to Update the Subject with SubjectID=1, to change the ValueID to only 1 where the AttributeID is 1, so
Before:
Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1 1 2
1 1 3
After:
Select * from Subject WHERE SubjectID=1 AND AttributeID=1
--returns:
SubjectID AttributeID ValueID
1 1 1
I am doing this with a stored procedure with optional parameters (all null and update only the attributes that were provided), now this is not an issue. My question is:
What is the best practice to update this rows? I see the following answers as viable:
- Delete all the rows that contain the specified attribute, then insert the new ones;
- If there is only one attribute of that type (for the specified subject) update that one (not a good solution if there are more than 1 for the same attribute)
Any other ideas?