Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Allocate a unique number to each row

Author  Topic 

spowell
Starting Member

23 Posts

Posted - 2010-07-20 : 08:48:20
Hi

I have a table that has 2000 rows of information. I need to allocate a unique number to each row. Can anyone help me do this?

Thanks for reading

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-20 : 08:52:25
select
row_number() over (order by (select 1)) as unique_number,
*
from your_table

If that isn't what you want then be more specific please.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-20 : 08:53:52
select ROW_NUMBER()over(order by (select 1))as uniqueid,* from yourtable


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

spowell
Starting Member

23 Posts

Posted - 2010-07-20 : 10:21:25
Thank you both for your help
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-20 : 10:25:35
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-20 : 10:50:17
See what you can do with row_number() function
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -