|
robvolk
Most Valuable Yak
USA
15566 Posts |
Posted - 07/13/2012 : 09:35:50
|
SQL Server 2012 introduced sequences to accomplish that feature. If you can't upgrade you can try the following:
1. Add a rowversion column to all the tables you want to increment. 2. Make the ID columns default to CAST(@@DBTS as bigint)
@@DBTS is the database-level rowversion value. Any UPDATE or INSERT operations on a table with a rowversion column will increment it. Naturally the downside is that UPDATEs increment it as well as INSERTs, and it also increments even if the transaction rolls back. If you don't care about this behavior and just want an incrementing value, this is probably the easiest way to do it without sequences. |
 |
|