加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SqlServer查询数据库所有用户表的记录数

发布时间:2020-12-12 15:37:15 所属栏目:MsSql教程 来源:网络整理
导读:--创建临时表 ? create table #temp(Recordcount int,tableName varchar(30)) ? --用游标将查询的记录数,插入临时表 declare @tablename varchar(30) declare @sql varchar(100) declare @str varchar(30) declare tablecursor cursor for select name from

--创建临时表

?

create table #temp(Recordcount int,tableName varchar(30))

?

--用游标将查询的记录数,插入临时表


declare @tablename varchar(30)
declare @sql varchar(100)
declare @str varchar(30)
declare tablecursor cursor for
select name from sysobjects where xtype='u'
open tablecursor
fetch next from tablecursor into @tablename
while @@fetch_status=0
begin
set @str=@tablename
set @sql='insert into #temp(recordcount,tablename) select count(*),'+''''+@tablename+''''+' from
'+@tablename
exec(@sql)
fetch next from tablecursor into @tablename
end
close tablecursor
deallocate tablecursor

?

--查询临时表,即可看见一个数据库的每个表的记录数

?

select * from #temp

?

?

--最后删除临时表


drop table #temp

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读