T-SQL update an increasing value

I have a table with many columns, one column is called "aID" and currently has no value. I want to add an increasing value here, from 1 to the amount of rows in table.

UPDATE [xx].[dbo].[UserValues] 
SET aID = ??
Where aID is null

How can i do this?

Answers


Maybe query:

UPDATE t
SET t.aID = t.Rn
FROM (SELECT aID,
             ROW_NUMBER() OVER(ORDER BY aID) AS Rn   
      FROM [xx].[dbo].[UserValues]
      WHERE aID is null) t

Need Your Help

Facing PNGCrush issue on some of XCode / Mac OS (Not specific)

ios xcode macos png pngcrush

I have developed an application using Mac OS 10.7.5 and XCode 4.6.2. Application is working fine in my machine without any error/warnings.

How build my own Application Setting

java design-patterns configuration

I want to build a ApplicationSetting for my application. The ApplicationSetting can be stored in a properties file or in a database table. The settings are stored in key-value pairs. E.g.