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