两表删除问题
请教两个问题:一、两表记录比较,删除b1与b2的jnh不同的记录
create cursor b1 (jnh n(1),mc c(2))
insert into b1 values (1,"A1")
insert into b1 values (2,"A2")
insert into b1 values (3,"A3")
insert into b1 values (4,"A4")
insert into b1 values (5,"A5")
create cursor b2 (jnh n(1))
insert into b2 values (1)
insert into b2 values (3)
insert into b2 values (5)
现在删除b1中与b2的jnh不同的记录
delete b1 from b2 where b1.jnh<>b2.jnh
则b1被全部删除.
如果改为删除b1中与b2的jnh相同的记录
delete b1 from b2 where b1.jnh=b2.jnh
则正确。上一条语句问题在哪?
二、能否使两表同时删除jnh对应的记录?
create cursor b1 (jnh n(1),mc1 c(2))
insert into b1 values (1,"A1")
insert into b1 values (2,"A2")
insert into b1 values (3,"A3")
insert into b1 values (4,"A4")
insert into b1 values (5,"A5")
create cursor b2 (jnh n(1),mc2 c(2))
insert into b2 values (1,"B1")
insert into b2 values (2,"B2")
insert into b2 values (3,"B3")
insert into b2 values (4,"B4")
insert into b2 values (5,"B5")
两表jnh数相同
如b1中一条(或多条)记录被删除时,b2对应的jnh也同时被删除。谢谢!
[此贴子已经被作者于2020-1-3 18:27编辑过]