I have a table like this in SQL Server:
varID(PK) dataID(PK) is_used
A 1 0
B 1 0
Then I’m loading data to update is_used to 1 if the varID/dataID combo exists and add it in otherwise.
So I have to insert/update these varID/dataID combos.
varID(PK) dataID(PK)
B 1
C 1
So the updated table would look like this:
varID(PK) dataID(PK) is_used
A 1 0
B 1 1
C 1 1
What’s the easiest way to do this? I will do it in a stored procedure.
Procedure tries to update
is_usedgiven a key. If unsuccessful, inserts new row. Note I put 0 as default value for is_used – I think is_used = 1 for (C, 1) is an inadvertence.