SQLServer 例:a有3行数据,b有6行数据(三行与a相同),如何向a表插入b表中的那三行a表没有的数据?
1个回答
展开全部
create table A
(
id int not null,
sname varchar(10) not null,
age int not null
)
insert into A values (1,'123',12)
insert into A values (2,'234',12)
insert into A values (3,'345',12)
create table B
(
id int not null,
sname varchar(10) not null,
age int not null
)
insert into B values (1,'123',12)
insert into B values (2,'234',12)
insert into B values (3,'345',12)
insert into B values (4,'456',12)
insert into B values (5,'567',12)
insert into B values (6,'678',12)
--创建视图
create view v_B as
select * from B where B.id not in
(select id from A)
insert into A(id,sname,age) select id,sname,age from v_B
(
id int not null,
sname varchar(10) not null,
age int not null
)
insert into A values (1,'123',12)
insert into A values (2,'234',12)
insert into A values (3,'345',12)
create table B
(
id int not null,
sname varchar(10) not null,
age int not null
)
insert into B values (1,'123',12)
insert into B values (2,'234',12)
insert into B values (3,'345',12)
insert into B values (4,'456',12)
insert into B values (5,'567',12)
insert into B values (6,'678',12)
--创建视图
create view v_B as
select * from B where B.id not in
(select id from A)
insert into A(id,sname,age) select id,sname,age from v_B
更多追问追答
追问
不用视图可以么,因为这是我的一个存储过程的一部分
追答
用原视图的语句代替掉试图就行了
insert into A(id,sname,age) select id,sname,age from B where B.id not in(select id from A)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询