主頁 > 知識(shí)庫 > 參考sql2012存儲(chǔ)過程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例

參考sql2012存儲(chǔ)過程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例

熱門標(biāo)簽:外呼系統(tǒng)的話術(shù) 貴州外呼回?fù)芟到y(tǒng)是什么 云南全自動(dòng)外呼系統(tǒng)公司 衛(wèi)星地圖標(biāo)注距離 智能語音車載電話機(jī)器人 競圣地圖標(biāo)注服務(wù) 陽光創(chuàng)信ai外呼獲客系統(tǒng)助力 安陽天音防封電銷卡 智能外呼系統(tǒng)需要多少錢

可以結(jié)合sp_MSforeachdb再遍歷所有用戶數(shù)據(jù)庫查看所有表的尺寸大小,注意它的參數(shù)@sql不能超過nvarchar(2000),這里就不貼出代碼了。
另外還可以定期運(yùn)行并將結(jié)果保存下來,以便觀察數(shù)據(jù)變化趨勢。

查詢單個(gè)數(shù)據(jù)庫的所有用戶表尺寸大?。?/P>

復(fù)制代碼 代碼如下:

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

標(biāo)簽:湘潭 河源 周口 營口 寧夏 鄂爾多斯 預(yù)約服務(wù) 欽州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《參考sql2012存儲(chǔ)過程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例》,本文關(guān)鍵詞  參考,sql2012,存儲(chǔ),過程,寫的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《參考sql2012存儲(chǔ)過程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于參考sql2012存儲(chǔ)過程寫的統(tǒng)計(jì)所有用戶表尺寸大小的示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章