最近客戶的數(shù)據(jù)庫暴漲,一開始找不到原因,用sql查詢表的空間大小,結(jié)果之前用的sql語句只能查詢除了text,image外的字段大小.搞得一時(shí)間混亂不堪.后來咨詢了大師們,找到用sp_spaceused這個(gè)系統(tǒng)函數(shù)可以查詢表的真實(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 for select 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 end SELECT * 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)平臺(tái)是覆蓋了眾多的業(yè)務(wù)領(lǐng)域、行業(yè)應(yīng)用,蘊(yùn)涵了豐富的ERP管理思想,集成了ERP軟件業(yè)務(wù)管理理念,功能涉及供應(yīng)鏈、成本、制造、CRM、HR等眾多業(yè)務(wù)領(lǐng)域的管理,全面涵蓋了企業(yè)關(guān)注ERP管理系統(tǒng)的核心領(lǐng)域,是眾多中小企業(yè)信息化建設(shè)首選的ERP管理軟件信賴品牌。
轉(zhuǎn)載請(qǐng)注明出處:拓步ERP資訊網(wǎng)http://www.ezxoed.cn/
本文標(biāo)題:SQL計(jì)算數(shù)據(jù)庫表占用的真實(shí)空間大小
本文網(wǎng)址:http://www.ezxoed.cn/html/support/1112153687.html