最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2014年01月12日 10:58:43   作者:  
參考SQL2005, 2008和2012的系統(tǒng)存儲(chǔ)過(guò)程master.sys.sp_spaceused代碼后,寫(xiě)了下面一條語(yǔ)句來(lái)方便平時(shí)統(tǒng)計(jì)所有用戶(hù)表尺寸大小

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

查詢(xún)單個(gè)數(shù)據(jù)庫(kù)的所有用戶(hù)表尺寸大?。?/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

相關(guān)文章

最新評(píng)論

望江县| 原阳县| 合江县| 香河县| 云浮市| 宜丰县| 泸定县| 嘉义市| 诏安县| 田阳县| 六枝特区| 南召县| 亳州市| 汶上县| 通许县| 桂阳县| 中山市| 江安县| 禹州市| 苍南县| 朝阳市| 吐鲁番市| 白银市| 揭阳市| 琼结县| 蓝山县| 威信县| 古丈县| 大邑县| 石阡县| 格尔木市| 广元市| 乌鲁木齐市| 沙湾县| 威海市| 独山县| 康马县| 十堰市| 安图县| 靖江市| 曲阜市|