MYSQL replicates the record and inserts it into the current table

Source: Internet
Author: User

Example table

create table tb_demo(  id int unsigned auto_increment primary key,  title varchar(50) not null default '',  contents text,  add_time int unsigned default 0);
Inserting test data
insert into tb_demo (title,contents,add_time) values ('#1 title 001','CONTENT 001 ABCD 1111',unix_timestamp()),('#2 title 002','CONTENT 002 ABCD 2222',unix_timestamp()),('#3 title 003','CONTENT 003 ABCD 3333',unix_timestamp()),('#4 title 004','CONTENT 004 ABCD 4444',unix_timestamp());

Preview: \

Copy and insert

The following statement implements:

    • Avoid primary keys
    • Avoid other duplicate indexes (although not in the demo, the actual environment may be used)
    • Use random characters, and merge two of strings
    • Record Data Entry Time
mysql> insert into tb_demo (title,contents,add_time) select concat(id,'__',title),concat('COPY_',contents),unix_timestamp() from tb_demo order by id desc limit 3;Query OK, 3 rows affected (0.07 sec)Records: 3  Duplicates: 0  Warnings: 0

Execution Result:

MYSQL replicates the record and inserts it into the current table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.