|
|
First add a Column 'ID' to the table Customers
ALTER TABLE Customers
ADD ID int null
GO
Now execute the following code to insert data into the ID column based on some columns.
UPDATE temp
SET ID=Rowno
FROM
(
SELECT ID, ROW_NUMBER() OVER (ORDER BY [Country] asc, [City] asc, [Address] desc) AS Rowno
FROM Customers
)temp
The query shown above inserts data into the ID column based on the Country, City and Address fields
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |






comments
0 Responses to "Programmatically adding an ID field to a table in SQL Server"Post a Comment