删除a表中和b表相同的数据

create table a ( bm char(4), --编码 mc varchar(20) --名称 ) go insert into a values('1111','1111'); insert into a values('1112','1111'); insert into a values('1113','1111'); insert into a values('1114','1111'); insert into a values('1115','1111'); go select * into b from( select * from a where 1=2) as c; go insert into b values('1111','1111'); insert into b values('1112','1111'); insert into b values('1113','1111'); insert into b values('1114','1111'); select * from a select * from b go --方法1 delete from a where exists(select bm,mc from b where a.bm=b.bm and a.mc=b.mc) go insert into a values('1111','1111'); insert into a values('1112','1111'); insert into a values('1113','1111'); insert into a values('1114','1111'); go --方法2 delete from a where bm in (select bm from b where a.bm=b.bm and a.mc=b.mc) and mc in(select mc from b where a.bm=b.bm and a.mc=b.mc)

 

来自:http://www.doozz.com/View/30/300604/29027.html

你可能感兴趣的:(删除a表中和b表相同的数据)