declare @tbName nvarchar(500)
declare @ct int
declare @csql nvarchar(500)
declare #tb cursor for SELECT OBJECT_NAME (id) As TableName FROM sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0
open #tb
fetch next from #tb into @tbName
while @@fetch_status=0
begin
set @csql = N'Select @ct= Count(*) From ' + @tbName
Exec dbo.sp_executesql @csql,N'@ct int output',@ct output
Print @tbName + '---' + Cast(@ct As nvarchar(500)) -- 这里可以修改一下,打印出来,或者插入到临时表中都可以
fetch next from #tb into @tbName
end
close #tb
deallocate #tb 脚本查询 SQL数据库 各个表的 记录数
最新推荐文章于 2019-01-08 01:43:58 发布
本文将介绍如何使用SQL查询并统计系统中的自定义表,包括获取表名和执行复杂查询,实现数据的有效管理和分析。
3528

被折叠的 条评论
为什么被折叠?



