惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - 克隆

SVN快速入门(TSVN) C# HttpWebRequest提交数据方式浅析 简单的3个SQL视图搞定所有SqlServer数据库字典 敏捷开发Scrum 学习笔记,适于移动开发 团队的职责和任务之间的关系 精心收集的jQuery常用的插件1000 24款超实用的Web 2.0风格翻页代码 【转】使用 Entity Framework + ListView + DataPager 实现数据分页 (转)ASP.NET页面打印技术的总结 [转]数据库设计 Step by Step (5) [转]jquery插件弹出div SQLServer2008/2005 生成数据字典SQL语句 SQL HierarchyID 数据类型 OSWorkflow表结构分析 javascript动态创建VML [转]由于项目原因看了一下vml,写了一个Web工作流的设计器雏形! VML流程图 启用IIS的Gzip压缩 IIS压缩
简单统计SQLSERVER用户数据表大小(包括记录总数和空间占用情况)
克隆 · 2013-10-10 · via 博客园 - 克隆

在SQLSERVER,简单的组合sp_spaceused和sp_MSforeachtable这两个存储过程,可以方便的统计出用户数据表的大小,包括记录总数和空间占用情况,非常实用,在SqlServer2K和SqlServer2005中都测试通过。另外还有sp_MSforeachdb可以遍历所有数据库,使用方法详见SQL帮助。

/*
1. exec sp_spaceused '表名'            (SQL统计数据,大量事务操作后可能不准)
2. exec sp_spaceused '表名', true       (更新表的空间大小,准确的表空大小,但可能会花些统计时间)
3. exec sp_spaceused                    (数据库大小查询)
4. exec sp_MSforeachtable "exec sp_spaceused '?'"     (所有用户表空间表小,SQL统计数据,,大量事务操作后可能不准)
5. exec sp_MSforeachtable "exec sp_spaceused '?',true"    (所有用户表空间表小,大数据库慎用)
*/

create table #t(name varchar(255), rows bigint, reserved varchar(20), data varchar(20), index_size varchar(20), unused varchar(20))
exec sp_MSforeachtable "insert into #t exec sp_spaceused '?'" 
select * from #t
drop table #t

另外还有sp_MSforeachdb可以遍历所有数据库,使用方法详见SQL帮助。

专注数据库技术,学以致用。