--我加了 top 10 用的时候可以去掉
declare @select_alltableCount varchar(max)=''
;with T as (
select top 10 'SELECT '''+name+ '''as Table_Name, COUNT(1) as Row_Count From '+ name + char(10)+ ' union all ' as A from sys.objects where type='U' order by name asc
)
,T2 as (select val=(select ''+ A +'' from T for xml Path('')) )
select @select_alltableCount=val from T2
if(Len(@select_alltableCount)>9) SET @select_alltableCount=Left(@select_alltableCount,Len(@select_alltableCount)-9)
print @select_alltableCount
Execute( @select_alltableCount)