參考sql2012存儲(chǔ)過(guò)程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例
可以結(jié)合sp_MSforeachdb再遍歷所有用戶數(shù)據(jù)庫(kù)查看所有表的尺寸大小,注意它的參數(shù)@sql不能超過(guò)nvarchar(2000),這里就不貼出代碼了。
另外還可以定期運(yùn)行并將結(jié)果保存下來(lái),以便觀察數(shù)據(jù)變化趨勢(shì)。
查詢單個(gè)數(shù)據(jù)庫(kù)的所有用戶表尺寸大?。?/P>
Select @@servername as ServerName,db_name() as DBName ,object_id as ObjectID, schema_name(schema_id) as SchName, name as TableName
,Rowcnt as Rows,Columns,Indexes,RowLength
,ReservedKb, TableUsedKb
,UsedKb-TableUsedKb as IndexUsedKb,ReservedKb-UsedKb as UnusedKb
,create_date as CreateDate,modify_date as LastModifiedDate, getutcdate() as TrackingUTCTime
From
(select
object_id
,schema_id
,name
,(Select max(row_count) from sys.dm_db_partition_stats p with(nolock) where p.object_id=t.object_id and p.index_id < 2) as Rowcnt
,(Select Count(1) from dbo.syscolumns with(nolock) where id = t.object_id) as Columns
,(Select Count(distinct index_id) from sys.dm_db_partition_stats p with(nolock) where p.object_id=t.object_id) as Indexes
,(SELECT SUM(length) FROM dbo.syscolumns with(nolock) WHERE id = t.object_id) as RowLength
,IsNull((Select SUM(reserved_page_count) from sys.dm_db_partition_stats p with(nolock) where p.object_id=t.object_id),0)*8
+ IsNull((Select sum(reserved_page_count)
FROM sys.dm_db_partition_stats p2 with(nolock)
inner join sys.internal_tables it with(nolock) on p2.object_id = it.object_id
WHERE it.parent_id = t.object_id
AND it.internal_type IN (202,204,207,211,212,213,214,215,216,221,222,236)),0)* 8 as ReservedKb
,IsNull((Select SUM(in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count)
from sys.dm_db_partition_stats p with(nolock) where p.object_id=t.object_id and p.index_id < 2),0)* 8 as TableUsedKb
,IsNull((Select SUM(used_page_count) from sys.dm_db_partition_stats p with(nolock) where p.object_id=t.object_id),0)*8
+ IsNull((Select sum(used_page_count)
FROM sys.dm_db_partition_stats p2 with(nolock)
inner join sys.internal_tables it with(nolock) on p2.object_id = it.object_id
WHERE it.parent_id = t.object_id
AND it.internal_type IN (202,204,207,211,212,213,214,215,216,221,222,236)),0)* 8 as UsedKb
,create_date
,modify_date
from sys.tables t with(nolock)
where Type='U'
) A
order by ReservedKb desc
相關(guān)文章
sql實(shí)現(xiàn)split函數(shù)的腳本
這篇文章主要介紹了sql實(shí)現(xiàn)split函數(shù)的腳本,大家參考使用吧2013-11-11SQL?Server?DATEDIFF()?函數(shù)用法
這篇文章主要介紹了SQL?Server?DATEDIFF()?函數(shù)的定義和用法,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12SQL Server根據(jù)分區(qū)表名查找所在的文件及文件組實(shí)現(xiàn)腳本
這篇文章主要介紹了SQL Server根據(jù)分區(qū)表名查找所在的文件及文件組實(shí)現(xiàn)腳本,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-07-07重命名SQLServer數(shù)據(jù)庫(kù)的方法
本文講解重命名SQLServer 數(shù)據(jù)庫(kù),包括物理文件名、邏輯文件名的改名2012-07-07sqlserver之datepart和datediff應(yīng)用查找當(dāng)天上午和下午的數(shù)據(jù)
這篇文章主要介紹了sqlserver之datepart和datediff應(yīng)用查找當(dāng)天上午和下午的數(shù)據(jù),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08SQL Server 2012 多表連接查詢功能實(shí)例代碼
這篇文章主要介紹了SQL Server 2012 多表連接查詢功能實(shí)例代碼,需要的朋友可以參考下2017-01-01Sql Server中實(shí)現(xiàn)行數(shù)據(jù)轉(zhuǎn)為列顯示
這篇文章主要介紹了Sql Server中實(shí)現(xiàn)行數(shù)據(jù)轉(zhuǎn)為列顯示,文章基于Sql語(yǔ)句的相關(guān)資料展開如何實(shí)現(xiàn)數(shù)據(jù)轉(zhuǎn)為列顯的操作過(guò)程,需要的小伙伴可以參考一下2022-04-04