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 2000 Forums
 Transact-SQL (2000)
 prob. with primary key

Author  Topic 

erwine
Yak Posting Veteran

69 Posts

Posted - 2006-04-02 : 03:34:56
Hi all,
actually, writing SQL statement to filter data and then inserting it into new table is not that difficult. However, i always encountered problem with primary key, which is unique most of the time.

let's say :
table1
uniqueID ordername quantity desc.

i can get the data for ordername,quantity and desc from other tables, but because of uniqueID, it gives me no choice but to use cursor and add uniqueID to temp. table, then finally i insert into table1.

ofcoz, for uniqueID, i still need to get the highest no. (in this case uniqueID is integer incrementing 0-256 for example).

does anyone have better ideas? does SQL2005 have new feature for this?currently im using SQL2000.

regards'
erwine


... sql is fun...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-02 : 04:04:07
you can create the uniqueID as identity column.
example :
create table table1
(
uniqueID int identity,
...
)




KH

Choice is an illusion, created between those with power, and those without.
Go to Top of Page

erwine
Yak Posting Veteran

69 Posts

Posted - 2006-04-03 : 15:31:46
if i already have records inside the table?
obviously i need to get the last one and increment it. can identity automatically do it?


... sql is fun...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-03 : 19:21:30
use
select max(uniqueID) from table1




KH

Choice is an illusion, created between those with power, and those without.
Go to Top of Page
   

- Advertisement -