我想从10多个表中互相查询一下,看有没有重复行,请各位出个好招,多谢了

解决方案 »

  1.   

    --tryselect id from
    (
    select id from T1
    union all 
    select id from T2
    union all 
    select id from T3...union all
    select id from T10
    )a group by id having count(*)>1
      

  2.   

    --查所有以T开头的表有无重复记录
    declare @SqlStr varchar(8000)
    select @SqlStr='select id from('
    select @SqlStr=@SqlStr+'select id from ['+[name]+'] union all '
             from sysobjects where Xtype=N'U' and name like 'T%'
    select @SqlStr=left(@SqlStr,len(@SqlStr)-10)+') as x group by id having count(*)>1'
    exec(@SqlStr)