最近客戶的數(shù)據(jù)庫暴漲,一開始找不到原因,用sql查詢表的空間大小,結(jié)果之前用的sql語句只能查詢除了text,image外的字段大小.搞得一時間混亂不堪.后來咨詢了大師們,找到用sp_spaceused這個系統(tǒng)函數(shù)可以查詢表的真實大小,包含text等字段.sql如下:
declare @id NVARCHAR(100) create table #spt_space ( [name] NVARCHAR(50) null, [rows] int null, [reserved] NVARCHAR(50) null, [data] NVARCHAR(50) null, [index_size] NVARCHAR(50) null, [unused] NVARCHAR(50) null) set nocount on declare c_tables cursor forselect name from sysobjects where xtype = 'U' open c_tables fetch next from c_tables into @id while @@fetch_status = 0 begin /* Code from sp_spaceused */ insert into #spt_space ([name],[rows],reserved,data,index_size,unused) EXEC sp_spaceused @id fetch next from c_tables into @id endSELECT * FROM( SELECT *,CAST(REPLACE(reserved,'KB','') AS INT) AS reservedindex FROM #spt_space ) c order by c.reservedindex desc drop table #spt_space close c_tables deallocate c_tables |
核心關(guān)注:拓步ERP系統(tǒng)平臺是覆蓋了眾多的業(yè)務領(lǐng)域、行業(yè)應用,蘊涵了豐富的ERP管理思想,集成了ERP軟件業(yè)務管理理念,功能涉及供應鏈、成本、制造、CRM、HR等眾多業(yè)務領(lǐng)域的管理,全面涵蓋了企業(yè)關(guān)注ERP管理系統(tǒng)的核心領(lǐng)域,是眾多中小企業(yè)信息化建設(shè)首選的ERP管理軟件信賴品牌。
轉(zhuǎn)載請注明出處:拓步ERP資訊網(wǎng)http://www.shjqjggc.cn/
本文標題:SQL計算數(shù)據(jù)庫表占用的真實空間大小
本文網(wǎng)址:http://www.shjqjggc.cn/html/support/1112153687.html
























