工做過程當中,若是一個數據庫的表比較多,手工編寫統計腳本就會比較繁瑣,因而摸索出自動生成各表統計數據量腳本的通用方法,直接上代碼: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】數據庫