Thursday 10 January 2013

Update a column with sequential values

while working i needed a new column in my table, a sequential one. What i did was added a new column but  there was a problem either i have to accept nulls or set any default values for that column, it was not my requirement. I added a new one with default to null and then updated that table this way.




now to update NewSeqCol to a sequential value below is the query

DECLARE @VAR INT
SET
@VAR=
0 UPDATE MYTABLE
SET @VAR= NewSeqCol= @VAR+
1
GO
SELECT * FROM
MYTABLE
GO



here are results 


 

 you can update column with the required sequence gap  ;)

No comments:

Post a Comment