工做过程当中,若是一个数据库的表比较多,手工编写统计脚本就会比较繁琐,因而摸索出自动生成各表统计数据量脚本的通用方法,直接上代码:html
/* 脚原本源:https://www.cnblogs.com/zhang502219048/p/10970193.html */ create table #t(TableName nvarchar(200), Num int) exec sp_MSforeachtable 'insert into #t select ''?'', count(*) from ?' select replace(replace(TableName,'[',''),']','') as TableName, Num from #t order by Num desc drop table #t
以在ReportServer数据库中运行这个脚本为例,运行结果以下图(表名、数据量):sql
后记:
以上是本人在实际工做中遇到的sql server编写通用脚本自动统计各表数据量的一劳永逸解决办法,特此分享一下,但愿对遇到一样问题的朋友有所帮助。若是帮助到了你,欢迎给我打赏支持一下哦。
【转载请注明博文来源:http://www.javashuo.com/article/p-hulilzsh-dy.html】数据库