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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:11:04+00:00 2026-05-18T01:11:04+00:00

This mysql table has an autoincrement field. I want to duplicate some rows. I

  • 0

This mysql table has an autoincrement field. I want to duplicate some rows. I thought I will use a temporary table:

CREATE TEMPORARY TABLE tmptab SELECT * FROM mytab WHERE somecondition = 1;

Before copying the data back to mytab I can now do some updates in tmptab.

UPDATE tmptab ... /* some updates */;

Because mytab has an autoincrement field I cannot simply copy the contents of tmptab to mytab. One solution would be to enumarate fields (and omit the autoincrement field).

I am looking for a solution without enumerating fields. This has advantages, for instance when fields will be added later.

I thougth I could erase the autoincrement field in tmptab (removing the autoincrement column) and then use a query similar to this one:

INSERT INTO mytab SELECT *  FROM tmptab;

Would this work? The autoincrement field in mytab should be set correctly. Or is there a better way to do it?

  • 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-18T01:11:04+00:00Added an answer on May 18, 2026 at 1:11 am

    I thougth I could erase the autoindex field in tmptab (removing the autoindex column) and then use a query similar to this one

    You need to use a command like this:

    UPDATE tmptab SET key_column=NULL
    

    When you insert NULLs back into the original table, it will generate new auto_increment ids.

    You might need to add a command to drop the primary key index on the temp table for this to work.

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

Sidebar

Related Questions

I want to accomplish this (mysql) query: UPDATE table SET field = field +
I want to create a table that has a birthday date, this column shouldn't
I have a mySQL table that has a column like this: ID ----- 0352
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
In this MySQL table definition: CREATE TABLE groups ( ug_main_grp_id smallint NOT NULL default
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field
There is a MySQL table which has this definition taken from SQLYog Enterprise :
I have a table in MySQL that has 3 fields and I want to
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
I have this mysql table called comments which looks like this: commentID parentID type

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.