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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:55:48+00:00 2026-06-05T10:55:48+00:00

I have a large table of data with a new field added called uniq_id

  • 0

I have a large table of data with a new field added called uniq_id what I am looking for is a query I can run that will update and increment this field for each row, without having to write a script to do this.

Any ideas?

  • 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-05T10:55:50+00:00Added an answer on June 5, 2026 at 10:55 am

    What other columns does the table have? If you define the new column with AUTO_INCREMENT MySQL will fill it with sequential values starting from 1. There’s a catch though: the column has to be a key, or at least a part of the key (see the documentation for details). If you don’t have a primary key in the table already, you can simply do this:

    alter table MyTable add uniq_id int auto_increment, add primary key (uniq_id);
    

    If you can’t change the keys in the table and just want to fill the values of the new column as a one-off thing, you can use this update statement:

    update MyTable set uniq_id = (@count := coalesce(@count+1, 1));
    

    (coalesce returns its first non-null argument; it effectively establishes the value of the column for the first row.)

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

Sidebar

Related Questions

I have a large table of data (that displays test data) that is separated
Say, we have a table with some large text field containg jpg-files' binary data.
I have a field in a table that I will be storing different kinds
I have one large database table of request data, much like Apache request logs,
I have a relatively large table (5,208,387 rows, 400mb data/670mb index), all columns i
I have just create a large table with more than 30 rows of data,
I have a table with large amount of data and want to take too
I have a table. A large table with 25 columns each containing atomic data
I have a data table containing multiple columns and one column that stores somewhat
I have a large table that I'm trying to break up. For example I

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.