博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SqlServer查询数据库所有用户表的记录数
阅读量:7190 次
发布时间:2019-06-29

本文共 691 字,大约阅读时间需要 2 分钟。

--创建临时表

 

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
exec(@sql)
fetch next from tablecursor into @tablename
end
close tablecursor
deallocate tablecursor

 

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

 

select * from #temp

 

 

--最后删除临时表

drop table #temp

转载于:https://www.cnblogs.com/fhuafeng/archive/2013/05/28/3103049.html

你可能感兴趣的文章
java web servlet
查看>>
几个博客
查看>>
v4l2
查看>>
JS倒计时
查看>>
(new Function("return " + json))();
查看>>
mscrm 4.0 报表服务器报错
查看>>
SVM原理简介
查看>>
TLV----Demo讲解
查看>>
Mermaid js与流程图、甘特图..
查看>>
java 调度框架quartz
查看>>
hadoop exit code 退出码含义
查看>>
[C#基础知识系列]专题十:全面解析可空类型
查看>>
什么是.Net的异步机制(线程间通信) - step 5
查看>>
Lambda应用设计模式
查看>>
解决svn异常报错“”cleanup failed to process the following paths …… previous operation has not finished”...
查看>>
富文本框--FreeTextBox的使用
查看>>
koa2使用阿里云oss的nodejs sdk实现上传图片
查看>>
简单select(2)
查看>>
pandas基础学习
查看>>
用实例一步步教你写Jquery插件
查看>>