Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Mon, 12 Mar 2007 @ 17:29:36 GMT


     
  <Prev Next>  
<<First
<Prev
Next> Last>>  


Subj:   Incrementing field with an INSERT
 
From:   Barrow, Martin

Hi,

I have created a table that has a unique id that is incremented by 1 every time a row is inserted.

I started with the following to initially populate the table:

     CREATE SET TABLE identity_test ,
     CHECKSUM = DEFAULT
         ( Test_Index INTEGER NOT NULL,
            cidpersid integer
          );

     Insert into identity_test
     select row_number () over (order by cidpersid)
             ,cidpersid
     from training.cid_persons;

and then this when doing further inserts:

     Insert into identity_test (test_Index, CIDPERSID)
     Select maxid + 1
              ,888888
     from (select max(test_index) from identity_test ) a (maxid);

The insert above works fine when only inserting a row at a time, but how can I add a bunch of inserts (i.e. Insert select from another table) and get it to increment the Test_Index, starting at the current max?


Cheers,

Martin



     
  <Prev Next>  
<<First
<Prev
Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023