下面一段代码给大家介绍mysql 根据一个表数据更新另一个表的某些字段,具体代码如下所示:
drop table if exists t_u_template; -- 模版表 create table t_u_template ( id int not null auto_increment comment '模版表id', template_code varchar(50) binary comment '模版编码', template_name varchar(300) binary comment '模版名称', create_time datetime default null comment '创建时间', create_by varchar(64) character set utf8 collate utf8_general_ci not null comment '创建者' , update_by varchar(64) character set utf8 collate utf8_general_ci comment '更新者' , update_date datetime comment '更新时间' , constraint pk_u_template primary key (id) )default charset=utf8 comment '模版表'; drop table if exists template_temp_create; -- 模版临时表 create table template_temp_create ( id int not null auto_increment comment '模版表id', object_id varchar(50) binary comment '模版编码', operater_name varchar(64) character set utf8 collate utf8_general_ci not null comment '更新者' , create_time datetime not null comment '更新时间' , constraint pk_u_template primary key (id) )default charset=utf8 comment '模版临时表'; -- 修改创建人创建时间到t_u_template表 update t_u_template a,template_temp_create b set a.create_time=b.create_time where a.template_code = b.object_id; update t_u_template a,template_temp_create b set a.create_by=b.operater_name where a.template_code = b.object_id ;
总结
以上所述是小编给大家介绍的mysql 根据一个表数据更新另一个表的某些字段,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
网友评论