How to copy a row and insert in same table with a autoincrement field in MySQL?

后端 未结 13 1076
旧时难觅i
旧时难觅i 2020-11-29 15:55

In MySQL I am trying to copy a row with an autoincrement column ID=1 and insert the data into same table as a new row with

13条回答
  •  盖世英雄少女心
    2020-11-29 16:33

    This helped and it supports a BLOB/TEXT columns.

    CREATE TEMPORARY TABLE temp_table
    AS
    SELECT * FROM source_table WHERE id=2;
    UPDATE temp_table SET id=NULL WHERE id=2;
    INSERT INTO source_table SELECT * FROM temp_table;
    DROP TEMPORARY TABLE temp_table;
    USE source_table;
    

提交回复
热议问题