SequenceId is an auto-incrementing identity column, but isn’t the primary key.
What I want to happen is that when a row is updated, SequenceId is set to the next available value, e.g.:
_____________________
| SequenceId | Name |
| 1 | John |
| 2 | Jane |
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Update John to Jack. SequenceId is set to the next available identity value.
_____________________
| SequenceId | Name |
| 3 | Jack |
| 2 | Jane |
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Is this possible with SQL Server? If not, what would be an alternative?
I don’t think you can, at least not easily or cleanly. Why not use a ROWVERSION column? ROWVERSION columns are updated every time the row is updated to a new unique incrementing value in the database. You can create a computed column that converts it to a bigint if you want to index it. The downside is that timestamps are database-wide so you could get skipped numbers if you have multiple tables that use them.
FIDDLE
[EDIT] – updated to use RowVersion since Timestamp is deprecated