参考sql2012存储过程写的统计所有用户表尺寸大小的示例
发布时间:2024-01-25 05:50:18
标签:sql2012,用户表尺寸
可以结合sp_MSforeachdb再遍历所有用户数据库查看所有表的尺寸大小,注意它的参数@sql不能超过nvarchar(2000),这里就不贴出代码了。
另外还可以定期运行并将结果保存下来,以便观察数据变化趋势。
查询单个数据库的所有用户表尺寸大小:
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


猜你喜欢
- 本文实例讲述了MySQL 事务概念与用法。分享给大家供大家参考,具体如下:事务的概念MySQL事务是一个或者多个的数据库操作,要么全部执行成
- 效果展示效果展示素材展示一个为视频,另一个为像素大小不小于视频的封面。实现过程调用已启用的浏览器通过调用已启用的浏览器,可以实现直接跳过每次
- 这两天在搞Theano,要把mat文件转成pickle格式载入Python。Matlab是把一维数组当做n*1的矩阵的,但Numpy里还是有
- 通过@classmethod 实现多态1.概述python中通常使用对象创建多态模式,python还支持类创建多态模式。下面通过一个例子展示
- 一、字符串的本质1.字符串的定义golang中的字符(character)串指的是所有8比特位字节字符串的集合,通常(非必须)是UTF-8&
- chomp是用来删除换行符.#!/usr/bin/perl $c="abcde"; chomp($c); print &
- 自定义比较排序/运算符Python3和Python2相比有挺多变化。在Python2中可以直接写一个cmp函数作为参数传入sort来自定义排
- 在搭建springmvc框架时,底层使用hibernate4.1.8,数据库使用mysql5.1,使用hibernate自动生成数据库表时,
- 环境:numpy,pandas,python3在机器学习和深度学习的过程中,对于处理预测,回归问题,有时候变量是时间,需要进行合适的转换处理
- 这里就不给大家废话了,直接上代码,代码的解释都在注释里面,看不懂的也别来问我,好好学学基础知识去!# -*- coding: utf-8 -
- fileinput模块可以对一个或多个文件中的内容进行迭代、遍历等操作。该模块的input()函数有点类似文件readlines()方法,区
- 背景有时候爬虫爬过的url需要进行指纹核对,比如Scrapy就是进行指纹核对,如果是指纹重复则不再爬取。当然在入库的时候我还是需要做一次核对
- excel中有图片是很常见的,但是通过python读取excel中的图片没有很好的解决办法。网上找了一种很聪明的方法,原理是这样的:1、将待
- 本文实例为大家分享了Python端口扫描的实现代码,供大家参考,具体内容如下获取本机的IP和端口号:import socket def ge
- IE 开发团队更改了 IE8 的 User-agent ,更改的部分信息如下:IE8 on Windows Vista (Compatibi
- PRD的作用之一在于,保留产品设计初衷,期望达到什么样的目的,起到事后验证的效果。产品初衷需要做到利益最大化,找最大的蛋糕,为最大目标人群服
- 爬取过程:你好,李焕英 短评的URL:https://movie.douban.com/subject/34841067/comments?
- Python字符串处理学习中,有一道简单但很经典的题目,按照单词对字符串进行反转,并对原始空格进行保留: 如:‘ I love China!
- 题目:求一个3*3矩阵对角线元素之和。程序分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出。 def two_dime
- 编写一个prod()函数,可以接受一个list并利用reduce()求积。from functools import reducedef p