Monday, January 22, 2007

Add Counter (sequential Identity) Data in table

If you ever have the need to add a column with sequential Identity data in a table this SQL code will do the trick...

1: Table should have a column for this data with datatype int

2: Insert data in column:
DECLARE
@intCounter int

SELECT
@intCounter = 0

UPDATE T
SET
@intCounter = T.Counter = @intCounter + 1
FROM
dbo.table1 AS T

No comments: