Link to home
Start Free TrialLog in
Avatar of pvsbandi
pvsbandiFlag for United States of America

asked on

Auto Increment in Insert into Select

Hi,

  I'm on DB2 UDB 8.2.
   I have a table TB_INS_JOB(A INT, B VARCHAR(20),C VARCHAR(10));
   I'm doing the following:

       INSERT INTO TB_INS_JOB(B,C)
        SELECT B,C FROM TB_CP_JOB;

When i insert the values into TB_INS_JOB, i want the values in the column to Auto Increment, for each row inserted.
 
  How can i do it? Please advise.
Avatar of simpsol
simpsol
Flag of United States of America image

I do not know the exact thing in DB2, but probably example from other database might get you on the right track. The Auto Increment is referred as follows in the following database

Micorosft Access : AutoNumber
Microsoft SQL : Identity
Oracle: Sequence

DB2 might have something similari.

ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi simpsol,

Actually, the DDL for an auto increment column is different for SQL Server, MySQL, DB2, and Oracle.  Just substituting the keyword 'IDENTITY' with 'AUTOINCREMENT' isn't enough.


Kent
Avatar of pvsbandi

ASKER

Excellent!! Thanks!