最近客户的数据库暴涨,一开始找不到原因,用sql查询表的空间大小,结果之前用的sql语句只能查询除了text,image外的字段大小.搞得一时间混乱不堪.后来咨询了大师们,找到用sp_spaceused这个系统函数可以查询表的真实大小,包含text等字段.sql如下:
| declare@id            NVARCHAR(100) createtable#spt_space (     [name]            NVARCHAR(50) null,     [rows]          intnull,     [reserved]       NVARCHAR(50) null,     [data]         NVARCHAR(50) null,     [index_size]        NVARCHAR(50) null,     [unused]         NVARCHAR(50) null)  setnocount on declarec_tables cursorforselectnamefromsysobjects wherextype = 'U' openc_tables fetchnextfromc_tables into@id  while @@fetch_status = 0 begin    /* Code fromsp_spaceused */     insertinto#spt_space ([name],[rows],reserved,data,index_size,unused)     EXECsp_spaceused @id     fetchnextfromc_tables   into@id  endSELECT* FROM( SELECT*,CAST(REPLACE(reserved,'KB','') ASINT) ASreservedindex FROM#spt_space ) c orderbyc.reservedindex desc droptable#spt_space closec_tables deallocatec_tables | 
核心关注:拓步ERP系统平台是覆盖了众多的业务领域、行业应用,蕴涵了丰富的ERP管理思想,集成了ERP软件业务管理理念,功能涉及供应链、成本、制造、CRM、HR等众多业务领域的管理,全面涵盖了企业关注ERP管理系统的核心领域,是众多中小企业信息化建设首选的ERP管理软件信赖品牌。
转载请注明出处:拓步ERP资讯网http://www.toberp.com/
本文标题:SQL计算数据库表占用的真实空间大小



 
	

 相关文章
  相关文章
 






















 
  
  
  
  
  
  
  
 