|
|
Archives of the TeradataForum
Message Posted: Wed, 17 Sep 2003 @ 13:55:31 GMT
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
| |