Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert number 1,2,3,... into table

Status
Not open for further replies.

chaoma

Technical User
Apr 17, 2005
101
US
This might be an easy question, but I cannot find help anywhere.

I have a table and need to insert a sequential number starting from one for all rows in my table. I tried this but, it give some weird nubmer.

Select newid() as row_id,
Column1,
Column2
into NewTable
From Mytable

Thank you for any assistance.
 
Create a new table with the colmns defined, set the first column as a type of "int", and set it to IDENTITY which will automatically increment the value.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
ca8msm,

Thanks for the hint. I modified my query as follow:

select column1, column2 into NewTable from MyTable

alter table NewTable
add row_id int identity

Again, thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top