CREATE TABLE ##temp( id int identity(1,1), TbName varchar(500) ) CREATE TABLE ##temp1( id int identity(1,1), TbName varchar(500) ) go insert into ##temp select t.name as TbName from SYS.tables t go declare @n int set @n=1 declare @tempid varchar(500) set @tempid=0 declare @rows int select @rows=count(*) from ##temp while @n <= @rows begin declare @tempid1 varchar(500) declare @sql varchar(500) declare @TbName varchar(500) select @TbName=TbName from ##temp where id = @n set @sql = ‘select count(*) from ‘+ @TbName; EXEC (@sql)--查询本表数据条数 select @TbName--查询本表表名 set @n = @n + 1 end
--Drop TABLE ##temp
--Drop TABLE ##temp1
时间: 2024-10-05 23:26:51