Page 1 of 1

Generating a surrogate key

Posted: Wed Aug 15, 2007 10:20 pm
by just4u_sharath
source: sequential file
surrogate key generator
target : dataset

I have data in sequential file and i am generating surrogate key and loading the data to the dataset. Today i am loading 100 records and i got a sequence of 1 to 100 using surrogate key generator. Now the issue is that next day when i am loading another 100 records i need to get a sequence from 101. can you please help me with this issue

thanks

Posted: Wed Aug 15, 2007 10:38 pm
by DSguru2B
Get the max of the table and feed that value as initial value to the surrogate generator stage.

Re: Generating a surrogate key

Posted: Wed Aug 15, 2007 10:47 pm
by reddy.vinod
just4u_sharath wrote:source: sequential file
surrogate key generator
target : dataset

I have data in sequential file and i am generating surrogate key and loading the data to the dataset. Today i am loading 100 records and i got a sequence of 1 to 100 using surrogate key generator. Now the issue is that next day when i am loading another 100 records i need to get a sequence from 101. can you please help me with this issue

thanks
using "KeyMgtGetNextValue" we can get unique values in server. Just it try in parallel.

Posted: Wed Aug 15, 2007 10:58 pm
by ArndW
The server routine "KeyMgtGetNextValue" won't work in PX unless you revert to using a BASIC transform stage and that is not recommended. The surrogate key generation is not designed to store the highest value used after a run for use in the next one. The use of a database sequence is usually the most efficient approach and the only drawback it has it that the generated surrogate key value is not returned to the program. If you don't need to know the value for additional processing in your job, then use your databases' sequence generators, otherwise you will need to get the highest value in the table as mentioned by DSGuru2b - but bear in mind that by using MAX you have no guarantee of concurrency and might get duplicate values when several processes are running at the same time.