关于mysql中复制表的问题

nightgoblin 2012-03-05 04:28:29
我想实现将表a中内容复制到表b中,而且只是复制表b在表a中不存在的记录。
我是以下代码实现的:

create table a
(id int,
a varchar(10));
go
create table b
(id int,
b varchar(10));

insert into b select * from a where id not in (select id from b);

虽然这些写是可以实现这个功能,但是如果数据量比较大的话,有几百万条,那这方法就很慢。请问高手还可以有其他方法吗?
...全文
47 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nightgoblin 2012-03-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 acmain_chm 的回复:]

你这是MS SQL吧。
[/Quote]
不是哦,是在mysql下的。
ACMAIN_CHM 2012-03-05
  • 打赏
  • 举报
回复
你这是MS SQL吧。
nightgoblin 2012-03-05
  • 打赏
  • 举报
回复
[Quote=引用楼主 nightgoblin 的回复:]
我想实现将表a中内容复制到表b中,而且只是复制表b在表a中不存在的记录。
我是以下代码实现的:
SQL code

create table a
(id int,
a varchar(10));
go
create table b
(id int,
b varchar(10));

insert into b select * from a where id not in (select……
[/Quote]

你这个速度会提高吗?如果用exits来写这句呢?
rucypli 2012-03-05
  • 打赏
  • 举报
回复
insert ignore into b select * from a where id not in (select id from b);

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧