100分求解!!关于数据库!!!(100分)

  • 主题发起人 snoopy33
  • 开始时间
S

snoopy33

Unregistered / Unconfirmed
GUEST, unregistred user!
是这样,数据库中有两个表A,B,都有唯一的标识字段id,
我怎么才能删除B表中所有A表没有的数据呢?
比如A:1 B:1
A:2 B:2
B:3
B:4 要删掉的是3,4 这两个数据。
 
形如:
delete from B where id not in (select id from A)
 
对啊,这可是基本功,呵呵
 
delete from B where b.id not in (select a.id from A)
 
delete from B where id not in (select id from A)感觉是写出来的
delete from B where b.id not in (select a.id from A)感觉是从SQL中粘过来的
推荐使用第一种:)
 
没错,是基本功啊[:)]
 
DELETE FROM B WHERE B.Id NOT IN ( SELECT id FROM a )
 
可以把两个数据库建立索引
用两个数据集tdate控件
一个用于打开A表,一个打开B表
把B表的每个数据到A表去查找
如果找不到就删除
只是一个思路,可以试一下
 
不一定对吧,3、4这两个数值楼主并没有说就是ID这个字段啊,
 
delete from B where id not in (select id from A)
 
delete B where id not in (select id from A)
 
多谢大家,基本上平均分了分数
 
顶部