mysql 复制记录
1. 复制一条记录写入源数据表
insert into table_name select * from A where xx=xx;
示例:
insert into tasks select * from tasks where task_id='f5ef77262f1c467ea9483e29a529bf58';
2. 复制一条记录,然后修改字段值后写入源数据表
2.1 将field1 字段修改为 xiaoming
insert into table_name select 'xiaoming',field2,field3... from A where xx=xx;
示例:
insert into tasks select '123456',job_id,job_type,status from tasks where task_id='f5ef77262f1c467ea9483e29a529bf58';
2.2 将field1 字段修添加后缀
insert into table_name select concat(field1,'-suffix'),field2,field3... from A where xx=xx;
示例:
insert into tasks select concat(task_id,'-preffix'),job_id,job_type,status from tasks where task_id='f5ef77262f1c467ea9483e29a529bf58';
3. 复制一条记录写入其他表
insert into table_name (filed1, field2, field3...) select (filed1, field2, field3...) from A where xxx=xxx;
如果文章对您有所帮助,可以点一下推荐