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.
| Author |
Topic |
|
nickmollberg
Starting Member
3 Posts |
Posted - 2005-07-11 : 16:19:12
|
I have 500,000 records...I need to set a 'Company code' A unique identifier for each one...What would the SQL update syntax be for doing this?Will this be able to run on that many records? Thank you in advance for any help you can give. |
|
|
Tekhne
Starting Member
3 Posts |
Posted - 2005-07-11 : 17:39:14
|
Depends on what kind of id you want. If you truly need a uniqueidentifier, then use: quote: Alter Table tablenameAdd Column Company_ID uniqueidentifier not nullUpdate tablename Set Company_ID = NewID()
If you just want a numeric identifier, use: quote: Declare @Counter intSet @Counter = 0Alter Table tablenameAdd Column Company_ID int not nullUpdate tablename Set @Counter = Company_ID = @Counter + 1
Hope this helps.. |
 |
|
|
nickmollberg
Starting Member
3 Posts |
Posted - 2005-07-11 : 20:56:11
|
| the column already exists, and this table is full with data.I need an UPDATE query that will make the first record to CompanyID = 1, and the last (the 500,000th record to CompanyID = 500,000So, set the first record to companyID1, then incrememnt each additional record by one.I guess I would need a loop in my SQL UPDATE to do this?Any ideas on syntax? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-07-11 : 21:14:22
|
| You can try this:http://www.sqlteam.com/item.asp?ItemID=765 |
 |
|
|
|
|
|