Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 17 Sep 2003 @ 13:55:31 GMT


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


Subj:   Re: How to create sys generated keys
 
From:   Fuller, Joe

Hi Doug,

I would not think row X row... way too slow. I would mload to a stage table then insert/select into your target as follows:

  INSERT
    INTO targettable
        (KeyColumn,
         col1,
         col2,
         col3...)
  SELECT MaxKey + CSUM(1,1),
         col1,
         col2,
         col3...
    FROM stagetable,
         (SELECT (COALESCE(MAX(keycolumn),0)) AS MaxKey
            FROM targettable);

Because this is a CROSS JOIN, the CSUM function will be applied for each row thus incrementing. The COALESCE takes care of the very 1st insert where there will be no rows in the target table.

Best Regards,

Joe Fuller
Sr Data Warehouse Consultant, DBA
Teradata Professional Services



     
  <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