I have a SQL Server table in the below format and I am looking for a solution to keep the QuestionOrder in the correct sequence for that QuestionnaireID when I delete a record from this table. So let's say I delete the row with ID = 3, the QuestionOrder column for all rows with QuestionnaireID = 1 will be updated to be in the right sequence starting from 1 to N.
| ID | QuestionnaireID | Question | QuestionOrder | ... |
|---|---|---|---|---|
| 1 | 1 | Question-1 | 1 | ... |
| 2 | 1 | Question-2 | 2 | ... |
| 3 | 1 | Question-3 | 3 | ... |
| 4 | 1 | Question-4 | 4 | ... |
| 5 | 1 | Question-5 | 5 | ... |
| 6 | 2 | Question-1 | 1 | ... |
| 7 | 2 | Question-2 | 2 | ... |