Search code examples
sqltemp-tables

Insert into table from a temp table without identity column ?


I need to insert into table with same column in temp table. without identity column of table which am inserting. Remaining columns of inserting table is contained in temp table.


Solution

  • You need to be able to generate primary key values on your own. With IBM DB2, I am using sequences to get those values. It would be good to know which RDBMS you are using.

    A statement matching your needs could look like that:

    INSERT INTO MYSCHEMA.MYTABLE 
    select (NEXTVAL FOR MYSCHEMA.ID_SEQUENCE) as ID, T.*
    from MYSCHEMA.MYTEMPTABLE T