写一个存储过程。。比较相同的ID的其它字段是否相同。。
create proc test
as
declare @id int
begin
declare cursor_id cursor for
select id from a
open cursor_id
fetch next from cursor_id into @id
while @fetch_status=0
begin
if not exists(select 1 from a,b where a.id=b.id and a.col1=b.col1 and a.col2.b.col2 and.........)
begin
insert into C select * from a where id=@id
insert into C select * from b where id=@id
end
end
同意楼上的说法
declare @exec varchar(8000)
set @exec =''
select @exec=@exec+' a.'+name+' =b.'+name+' and' from syscolumns where id=object_id('[your table]') and name<>'id'
set @exec=left(@exec,len(@exec)-3)
set @EXEC='select * into [new table] from [your table] a where
(select count(*) from c where c.id=a.id)>1 and
not exists ( select 1 from [your table] b where '+@exec+' and b.id=a.id) '
exec(@exec)
select * from [new table]