--如果是簡單的查找不一樣, select * from T1 where not exists(select 1 from t2 where t2.id=t1.id and t2.contents=t1.contents and t2.re=t1.re) --還寫了個游標的,多出的也算不同create table T1 ( ID char(15), Contents varchar(250), Re char(50) )create table T2 ( ID char(15), Contents varchar(250), Re char(50) ) Insert into T1 select '1001','不許動!','abcd' union all select'1001','你怎么了!','bcde' union all select '1001','你真是好样的!','abcd' union all select'1002','好想你呀!','wetc' union all select'1002','好想你呀!','jynd' union all select'1003','不許動!','klhg' union all select'1003','不許動!','klhg' Insert into T2 select'1001','不許動!','abcd' union all select '1001','你怎么了!','bcde' union all select'1001','你真是好样的!','abcd' union all select'1002','好想你呀!','wetc' union all select'1002','好想你呀!','bcde' union all select'1003','不許動!','klhg'declare @ID char(15),@Contents varchar(250),@Re char(50) select * into #t1 from T1declare c1 cursor for select * from T2 open c1 fetch next from c1 into @id,@contents,@re while @@fetch_status=0 begin set rowcount 1 delete #t1 where id=@id and contents=@contents and re=@re set rowcount 0 fetch next from c1 into @id,@contents,@re end close c1 deallocate c1select * from #t1 drop table #t1,t1,t2id contents re ------------------------------------------------- 1002 好想你呀! jynd 1003 不許動! klhg
select * from T1
where not exists(select 1 from t2 where t2.id=t1.id and t2.contents=t1.contents and t2.re=t1.re)
--還寫了個游標的,多出的也算不同create table T1
(
ID char(15),
Contents varchar(250),
Re char(50)
)create table T2
(
ID char(15),
Contents varchar(250),
Re char(50)
)
Insert into T1 select '1001','不許動!','abcd'
union all select'1001','你怎么了!','bcde'
union all select '1001','你真是好样的!','abcd'
union all select'1002','好想你呀!','wetc'
union all select'1002','好想你呀!','jynd'
union all select'1003','不許動!','klhg'
union all select'1003','不許動!','klhg'
Insert into T2 select'1001','不許動!','abcd'
union all select '1001','你怎么了!','bcde'
union all select'1001','你真是好样的!','abcd'
union all select'1002','好想你呀!','wetc'
union all select'1002','好想你呀!','bcde'
union all select'1003','不許動!','klhg'declare @ID char(15),@Contents varchar(250),@Re char(50)
select * into #t1 from T1declare c1 cursor for
select * from T2
open c1
fetch next from c1 into @id,@contents,@re
while @@fetch_status=0
begin
set rowcount 1
delete #t1 where id=@id and contents=@contents and re=@re
set rowcount 0
fetch next from c1 into @id,@contents,@re
end
close c1
deallocate c1select * from #t1
drop table #t1,t1,t2id contents re
-------------------------------------------------
1002 好想你呀! jynd
1003 不許動! klhg