Home > Database > Mysql Tutorial > MySQL复制表字段到另外一个表的字段

MySQL复制表字段到另外一个表的字段

WBOY
Release: 2016-06-07 16:24:25
Original
1847 people have browsed it

有时候,我们需要复制某个字段一整列的数据到另外一个新的字段中,这很简单,SQL可以这么写: UPDATE tb_1 SET content_target = content_source; 大概写法如下: Update {your_table} set {source_field} = {object_field} WHERE cause 有Navicat等工具更好

有时候,我们需要复制某个字段一整列的数据到另外一个新的字段中,这很简单,SQL可以这么写:

UPDATE tb_1 SET content_target = content_source;
Copy after login

大概写法如下:

Update {your_table} set {source_field} = {object_field} WHERE cause
Copy after login

有Navicat等工具更好,可以直接选中一列数据,拷贝粘贴到你需要的列中。如果是同一个表那没什么问题,如果是新表,请保持它们的行数是一致。如果行数不一致,你可以新建一个表,再把列拷贝进去,这样id数也会保持一致。

有时候这些MySQL界面工具会报错,这个时候用命令行更好。比如复制一个表字段数据到另外一个表的字段,可以这么写:

UPDATE tb_1 INNER JOIN tb_2 ON tb_1.tid = tb_2.tid
SET tb_1.tcontent = tb_2.tcontent
Copy after login

下面是一个实际例子,将PHPCMS已生成的静态页面的链接写入phpcms_content表中的url字段:

先这样拼凑出需要的url字段列。

SELECT CONCAT(FROM_UNIXTIME(inputtime,'%Y/%m%d'), '/', contentid, '.html') AS dt FROM phpcms_content ORDER BY contentid DESC
Copy after login

然后再查询编辑器(navicat)中,将整段复制拷贝到phpcms_content表中的url列即可。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template