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

  • Home
  • SEARCH
  • 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 8246865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:39:01+00:00 2026-06-07T22:39:01+00:00

I have duplicated (copied) a table and for some reason Primary Keys wasnt added.

  • 0

I have duplicated (copied) a table and for some reason Primary Keys wasnt added.
Now I have a lot of new records were added recently with 0 value in the id field. All the previous records does have a unique ID (from 1 to 302979).

How to fix this?

#1062 - Duplicate entry '0' for key 'PRIMARY'

AUTO_INCREMENT wasnt added as well.

CREATE TABLE `result` (
  `id` int(11) NOT NULL DEFAULT '0',
  `status` varchar(50) NOT NULL,
  `status_date` datetime NOT NULL,
  `member_id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
  • 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-07T22:39:03+00:00Added an answer on June 7, 2026 at 10:39 pm

    try

    update result
    inner join (select @row := (select max(id) from result)) r
    set id = (@row := @row + 1)
    where id = 0
    

    to correct the wrong ids.

    then add auto_increment to your table

    ALTER TABLE `result` CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT,
    ADD PRIMARY KEY (`id`) ;
    

    and then use

    ALTER TABLE result AUTO_INCREMENT = 1234;
    

    in which you replace 1234 with the number you want to start your increment value. It can be the highest id + 1 for instance. You could get that number with

    select max(id)+1 from result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with rows like id, length, time and some of them
Using Doctrine DBAL, I have some code that inserts a new row into the
I have a duplicated configuration file under WEB-INF directory, called configDEV.properties and configPRO.properties (one
I have a List object and I want to remove the duplicated items but
My aim is to have a picture drawn on one device to be duplicated
Working on a project where they have lots of enums and lots of duplicated
I'm using MySQL 4.1. Some tables have duplicates entries that go against the constraints.
I made a mistake in a bulk insert script, so now i have duplicate
Using MySQL 5 I have a table like this: date (varchar) door (varchar) shift
I have a table where I save all row-changes that have ever occurred. The

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.