Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 17 Sep 2003 @ 13:50:45 GMT


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


Subj:   Re: How to create sys generated keys
 
From:   Narayan Murthy K S

Just a thought!

How about something as follows:

Assume you have a table with the following definition:

Table : IdColGen
      Tablename varchar(30)
      Nextrec int

Now you would load the IdColGen with the tablename of the table for which you would want to generate the sequence number.

Say for table t1(seqno int, i int, j int)
Insert into IdColGen('t1',1);

Now when ever you would insert a new row into your table(user table) you would do an INSERT SELECT from the IdColGen table get the nextrec(your sequence number) and then supply the other values for the table.

Like :
      Insert into t1
            Sel IdColGen.nextrec,1,2
                  Where IdColGen.tablename = 't1';

Now in order to see a next sequence number being generated for the table 't1' you could write an INSERT TRIGGER on 't1' and update the Nextrec value associated with 't1' in IdColGen.

Narayan.



     
  <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