Incrementing an Integer in SQL Server

Viewed 41534

Noob question here, every time I change a certain record in an SQL Server 2008 R2 table, I want to increment a RevisionId record; to do so, I'm using the following syntax:

UPDATE TheTable
SET RevisionId=(SELECT RevisionId
                FROM TheTable
                WHERE Id=@id) + 1
WHERE Id=@id;

Btw, I'm going to put this into a trigger so that this happens automagically, but while this code works, it feels pretty clunky—any cleaner way to do this?

3 Answers
Related