Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:15:56+00:00 2026-05-31T14:15:56+00:00

I use the following statement to generate my primary key. table2 keeps the curent

  • 0

I use the following statement to generate my primary key. table2 keeps the curent primary key. But it is too slow. How can i optimize this proces.

update table1 t set ID =ROW_NUMBER() OVER ();

update table1 t 
set ID = (Select NUMGEN.currentvalue + ID from  table1 data, table2 NUMGEN 
where NUMGEN.tablename = 'table1' and t.Id = data.ID  );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:15:59+00:00Added an answer on May 31, 2026 at 2:15 pm

    Why are you doing primary keys this way. Why would you need to dynamically generate/modify your own id values?

    If you need a unique generated id for a table, create a sequence and use that sequence value in your table. For example:

    CREATE SEQUENCE <schema>.SEQ_SAMPLE_TABLE DATA TYPE BIGINT INCREMENT BY 1 NO ORDER NO CYCLE MINVALUE 100 MAXVALUE 9223372036854775807 CACHE 20;
    

    to get a unique sequence to use as your primary key.

    Then create a table with an ID as the primary key:

    CREATE TABLE <schema>.SAMPLE_TABLE ( 
        STATUS_ID BIGINT DEFAULT NULL , 
        STATUS_DESC VARCHAR(80) DEFAULT NULL , 
        CONSTRAINT <schema>.XPK_STATUS PRIMARY KEY( STATUS_ID ) );
    

    and then to insert a row, you do:

     insert into SAMPLE_TABLE (nextval for SEQ_SAMPLE_TABLE, 'This is working');
    

    Most of this can come from the db2 manuals.

    For example: Create Table: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0000927.htm

    Create Sequence: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0004201.htm


    EDIT: I should add — the above is how we’re doing it at my current client. Another way (perhaps better) is:

    CREATE TABLE WIDGET_INVENT 
        ( ROW_ID INT NOT NULL GENERATED ALWAYS AS IDENTITY 
                         (START WITH 1, INCREMENT BY 1, NO CACHE), 
          WIDGET_NO CHAR(6), 
          INV_COUNT INT WITH DEFAULT 0 
        ); 
    

    where you don’t specify the sequences externally, but just build them into the table definition. In this case, when doing inserts, just don’t reference the row_id column at all. For example, see here: http://www.ibm.com/developerworks/data/library/techarticle/0205pilaka/0205pilaka2.html

    The first way, where you specify your own sequences, was partially done that way because of how they migrate some tables from one environment to the next. Sequences get mapped out from different sources with different start values, allowing easy merging of data. YMMV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following jquery statements but i get error in this function onGetDataSuccess(result)
I use the following statement prepared and bound in ODBC: SELECT (CASE profile WHEN
What should I use in the following statement? Include or required. if(a ==b){ require
My select statement in PHP is select * from table; I use the following
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
I use the following jquery statements, $(.resultsdiv:odd).css(background-color, #fff); $(.resultsdiv:even).css(background-color, #EFF1F1); $('.resultsdiv').hover(function() { $(this).css('background-color', '#f4f2f2');
Table has surrogate primary key generated from sequence. Unfortunately, this sequence is used for
I use the following statement to shuffle the data in a range (for example
I use the following jQuery statements and I am getting the error, jQuery.parseJSON is
I use the following the jquery statements to call my php controller function, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.