我想把数据库中所有的表,每个有多少条数据全部统计出来
1个回答
展开全部
declare @ssql nvarchar(4000)
declare @name varchar(100)
declare @tReturn table(name varchar(100),num int)
declare @i int,@count int,@num int
declare @t table(i int,name varchar(100))
insert into @t(name) select name from dbo.sysobjects where type = 'U'
set @i=0
update @t set i=@i,@i=@i+1
select @count=count(*) from @t
set @i=1
while @i<=@count
begin
select @name=name from @t where i=@i
set @ssql= N'select @num=count(*) from '+@name
exec sp_executesql @ssql,N'@num int out',@num out
insert into @tReturn values(@name,@num)
select @i=@i+1
end
select * from @tReturn order by num
--在sql数据库后台运行
declare @name varchar(100)
declare @tReturn table(name varchar(100),num int)
declare @i int,@count int,@num int
declare @t table(i int,name varchar(100))
insert into @t(name) select name from dbo.sysobjects where type = 'U'
set @i=0
update @t set i=@i,@i=@i+1
select @count=count(*) from @t
set @i=1
while @i<=@count
begin
select @name=name from @t where i=@i
set @ssql= N'select @num=count(*) from '+@name
exec sp_executesql @ssql,N'@num int out',@num out
insert into @tReturn values(@name,@num)
select @i=@i+1
end
select * from @tReturn order by num
--在sql数据库后台运行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询