I’ve got a data set with a primary key, a foreign key and an empty sequence value. What is the fastest way of adding a sequence number to the data based on the foreign key?
QuestionConditionId is my primary key, QuestionId is foreign key. This is what the data looks like after selecting with an order by on QuestionId:

After the update my data should look like this:

I could write a loop for this, but I’m hoping for something smaller and more efficient. Any ideas?
But keeping this
Sequencecolumn synchronised after inserts, updates, deletes may be more hassle than it is worth. You can also useROW_NUMBERto calculate atSELECTtime rather than storing it.