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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert data to table with incremental key

Status
Not open for further replies.

mcginnism

MIS
Nov 18, 2002
5
US
I have a two tables one with 4265 records and another with 670 records that are setup identically but with different data. The first table has a primary key. So when I try to copy the data from one table to the other I get a duplicate key error.

So I'm trying to do an insert statement that will take all the data except the primary key and place it into the other table. Then in place of the primary key I want to insert an incremental number starting with 4266. The name of the primary key column is PLUKID. So far this is what I have minus the part with the incremental value.

INSERT INTO CRPDTA.F4305 (PLLOGH, PLDOCO, PLKCOO, PLSFXO, PLAN8, PLMCU, PLOMCU, PLLGTY, PLLGNO, PLDL01, PLSTSC)

SELECT PLLOGH, PLDOCO, PLKCOO, PLSFXO, PLAN8, PLMCU, PLOMCU, PLLGTY, PLLGNO, PLDL01, PLSTSC
FROM CRPDTA.F4305_013007
 
Create an Identity column, and use the seed of 4266, and an increment of 1

Jim
 
Can you explain how I would do it? I found this on the internet but I'm unsure about the values (9,0) what does the 9 and 0 refer to?


alter table stores
modify record_id numberic(9,0)
 
That is creating a numeric column. Look in books on line for Alter table and also Identity columns.

You specify a seed value, which is the value you want to start with, and an increment value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top