--计算一个数据库中所有表的大小
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 float(3))/(1024*1024) AS reservedindex FROM #spt_space
) c
order by c.reservedindex desc drop table #spt_space
close c_tables
deallocate c_tables

--粗算一个表的记录大小

declare @lengh int;
declare @i int;
declare @tableName varchar(20);
DECLARE @SQLString NVARCHAR(500) declare @a table (a int,b varchar(100)) ;
set @tableName='tblDetail'; 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
) insert into #spt_space ([name],[rows],reserved,data,index_size,unused)
EXEC sp_spaceused @tableName; declare @record_size int;
set @record_size = (select sum(length) from syscolumns where object_name(id)=@tableName);
select cast(rows as numeric(16))*@record_size /(1024*1024*1024) ,@record_size as record_size ,rows from #spt_space drop table #spt_space;

  

sqlserver计算表使用大小sql的更多相关文章

  1. SQLSERVER图片查看工具SQL Image Viewer5.5.0.156

    原文:SQLSERVER图片查看工具SQL Image Viewer5.5.0.156 SQLSERVER图片查看工具SQL Image Viewer5.5.0.156 在2013年某一次北京SQL ...

  2. 如何用Procmon.exe来监视SQLSERVER的logwrite大小

    如何用Procmon.exe来监视SQLSERVER的logwrite大小 在微软亚太区数据库技术支持组官方博客里面,你会发现很多篇文章都用到了Procmon.exe这个工具 今天我也介绍一下这个工具 ...

  3. navicat 连接sqlserver提示要安装 sql server native client

    navicat 连接sqlserver提示要安装 sql server native client 解决方法:其实navicat自带sqlncli_x64.msi,就在安装目录下,安装后问题解决!

  4. Access、SQLServer、Oracle常见SQL语句应用区别

    Access.SQLServer.Oracle常见SQL语句应用区别 关劲松 PMP 如果要兼容Access.SQL Server.Oracle三个数据库版本:我们在编写SQL语句的过程中,尽量使用一 ...

  5. 检测SQL Server表占用空间大小SQL

    检测SQL Server表占用空间大小SQL,要先选择需要查询的数据库,然后点击执行下面脚本. ),ROWS ),reserved ) ,Data ) ,index_size ) ,Unused ) ...

  6. SQLServer访问WebServices提示:SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问

    问题描述 在数据库中调用webservices, 提示:SQLServer访问WebServices提示:SQL Server 阻止了对组件 'Ole Automation Procedures' 的 ...

  7. [SQLServer]NetCore中将SQLServer数据库备份为Sql脚本

    NetCore中将SQLServer数据库备份为Sql脚本 描述: 最近写项目收到了一个需求, 就是将SQL Server数据库备份为Sql脚本, 如果是My Sql之类的还好说, 但是在网上搜了一大 ...

  8. Oracle 计算表占用空间大小

    我们可以通过系统视图DBA_SEGMENTS.USER_SEGMETNS.DBA_TABLES来查看一个表所占空间的大小,如下所示: SELECT SEGMENT_NAME TABLE_NAME ,S ...

  9. hibernate4中oracle,sqlserver,mysql数据库的sql方言配置(SQL Dialects)

    hibernate4中oracle,mysql,sqlserver数据库的sql方言配置(SQL Dialects) 数据库类型 Hibernate sql方言 DB2 org.hibernate.d ...

随机推荐

  1. oracle一列中的数据有多个手机号码用逗号隔开,我如何分别取出来?

    ID NUMBER1 137xxxx,138xxxx取出来成ID NUMBER1 137xxxx1 138xxxx create table test (id int, phone varchar2( ...

  2. Linux用户应知应会的7个‘ls’命令的独特技巧

    在前面我们系列报道的两篇文章中,我们已经涵盖了关于‘ls’命令的绝大多数内容.本文时‘ls命令’系列的最后一部分.如果你还没有读过该系列的其它两篇文章,你可以访问下面的链接. Linux中的15个基本 ...

  3. Log4j2在WEB项目中配置

    最近决定在新WEB项目中使用新的日志系统Log4j2. 官方介绍和学习文档网址为http://logging.apache.org/log4j/2.x/ 首先在WEB项目中引入以下几个jar包: ① ...

  4. [转]What you need to know about transimpedance amplifiers – part 1

    Transimpedance amplifiers (TIAs) act as front-end amplifiers for optical sensors such as photodiodes ...

  5. [SAP ABAP开发技术总结]日期函数

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. 系统分区MBR、GPT

    分区模式: ①MBR(主引导记录(Master Boot Record))分区:在驱动器最前端的一段引导扇区 缺点:主分区不超过4个,单个分区容量最大2TB 分区工具fdisk只能给硬盘做MBR分区, ...

  7. iOS案例:读取指定txt文件,并把文件中的内容输出出来

    用到的是NSString中的initWithContentsOfFile: encoding方法 // // main.m // 读取指定文件并输出内容 // // Created by Apple ...

  8. hdu 5950 Recursive sequence 矩阵快速幂

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  9. 用wordpress制作网站的总结

    在没有自己的网站的时候很像拥有一个属于自己的网站,可以说是自己的一个愿望吧.但是当我真正的运行起来了之后觉得没有多么的兴奋,自己也折腾了几天wordpress,从买域名空间,到安装WP,遇到了一些问题 ...

  10. JSON的操作

    今天遇到了一个要解析JSON的需求.在http://stackoverflow.com/questions/1826727/how-do-i-parse-json-with-ruby-on-rails ...