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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert sequential ID into table

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2009-01-28 : 09:37:54
Hi,

I've imported some data into a table but it doesn't contain any unique ID.

I've added a column ID and I want to update it to a sequential ID, i.e. 1,2,3,4 etc

How can this be done? Is there a rowID property or something like that I could use?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-28 : 09:39:38
just make it an identity column

ALTER TABLE tablename ADD columnname int IDENTITY(1,1)...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-28 : 09:40:37
and make sure you dont refer this column in insert & update statements. each insert will automatically increments value of this column so that you dont have to worry about it.
Go to Top of Page

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2009-01-28 : 09:48:46
Great, thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-28 : 09:52:27
welcome
Go to Top of Page
   

- Advertisement -