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 8703699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:55:34+00:00 2026-06-13T02:55:34+00:00

We hare having around 20,80,000 records in the table. We needed to add new

  • 0

We hare having around 20,80,000 records in the table.
We needed to add new column to it and we added that.

Since this new column needs to be primary key and we want to update all rows with Sequence
Here’s the query

BEGIN
FOR loop_counter IN 1 .. 211 LOOP
update user_char set id = USER_CHAR__ID_SEQ.nextval where user_char.id is null and rownum<100000;
commit;
END LOOP;
end;

But it’w now almost 1 day completed. still the query is running.
Note: I am not db developer/programmer.

Is there anything wrong with this query or any other query solution (quick) to do the same job?

  • 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-06-13T02:55:35+00:00Added an answer on June 13, 2026 at 2:55 am

    First, there does not appear to be any reason to use PL/SQL here. It would be more efficient to simply issue a single SQL statement to update every row

    UPDATE user_char
       SET id = USER_CHAR__ID_SEQ.nextval
     WHERE id IS NULL;
    

    Depending on the situation, it may also be more efficient to create a new table and move the data from the old table to the new table in order to avoid row migration, i.e.

    ALTER TABLE user_char
      RENAME TO user_char_old;
    
    CREATE TABLE user_char
    AS
    SELECT USER_CHAR__ID_SEQ.nextval, <<list of other columns>>
      FROM user_char;
    
    <<Build indexes on user_char>>
    <<Drop and recreate any foreign key constraints involving user_char>>
    

    If this was a large table, you could use parallelism in the CREATE TABLE statement. It’s not obvious that you’d get a lot of benefit from parallelism with a small 2 million row table but that might shave a few seconds off the operation.

    Second, if it is taking a day to update a mere 2 million rows, there must be something else going on. A 2 million row table is pretty small these days– I can populate and update a 2 million row table on my laptop in somewhere between a few seconds and a few minutes. Are there triggers on this table? Are there foreign keys? Are there other sessions updating the rows? What is the query waiting on?

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

Sidebar

Related Questions

I have a MySQL MyISAM table containing entries that describe airports. This table contains
I understand that Tortoise and Hare's meeting concludes the existence of a loop, but
I want to add a header row grouping the column headers. Departure Arrival <--
Can't i delete bulk objects like List<Person> prn = new List<Person>(); prn.Add(new Person {
Quoting the answer of Andrew Hare on the This Question . Object data sources
When I try to do this... Item[,] array = new Item[w, h]; // Two
I'm afraid that this is a very silly question, but I must be missing
Updated question given Andrew Hare's correct answer: Given the following C# classes: public class
This was one of the interview questions asked. How to find the length of
As Andrew Hare suggested in his answer : Create a field to store all

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.