我有两个不同列的表,如下所示:
table1
(
_id,
title,
name,
number,
address
)
table2
(
_id,
phone,
name,
address
)
Run Code Online (Sandbox Code Playgroud)
如何将数据'name','address'从table1复制到table2.
我的问题有两种情况:
Aar*_*lla 21
在SQL中复制的工作原理如下:
insert into table2 (name, address)
select name, address
from table1
Run Code Online (Sandbox Code Playgroud)
如果列的值id_相同,则需要插入和更新
insert into table2 (name, address)
select name, address
from table1 t1
where not exists (select * from table2 t2 where t1._id = t2._id)
;
update table2 t2 name = (select name from table1 t2 where t1._id = t2._id)
;
update table2 t2 address = (select address from table1 t2 where t1._id = t2._id)
Run Code Online (Sandbox Code Playgroud)
如果需要在数据库之间复制列,首先将它们导出到文件中(使用您喜欢的任何格式,例如CSV),然后手动将该文件合并到第二个数据库中,因为您无法编写一个说"使用"的SQL这些sqlite结构".
| 归档时间: |
|
| 查看次数: |
18924 次 |
| 最近记录: |