--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
--查所有以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)
(
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
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)