SQL:获取表子集的物理大小 [英] SQL: Getting the physical size of a subset of a table

查看:14
本文介绍了SQL:获取表子集的物理大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

sp_spaceused MyTable

有没有人知道一种找出只有特定数据子集占用多少空间的好方法?
因此,例如,如果我想通过从 MyTable 中删除所有 2 年之前的记录来找出我会减少多少空间.因此,不是 MyTable 使用的空间,我将获得 (SELECT * FROM MyTable WHEREAddedDate < '2010') 使用的空间.

Does anyone know a good way of finding out how much space only a certain subset of that data is taking up?
So, for example, if I want to find out how much space I would reduce by deleting all records from MyTable that are older than 2 years old. So instead of the space used by MyTable I would get the space used by (SELECT * FROM MyTable WHERE AddedDate < '2010').

谢谢

推荐答案

难道它不只是或多或少准确地移除了行的百分比?所以先统计总行数,再统计满足条件的行数,做除法.当然,要使该空间完全可用,您可能需要重建表和/或索引.

Wouldn't it just be more or less exactly the percentage of the rows removed? So count the total number of rows, then count the number of rows that meet the condition, and do the division. Of course for that space to become fully usable you may need to rebuild table and/or index.

我想如果您有可变长度数据并且某些行比其他行大得多,那么这种方法可能只是近似的,但在大多数情况下它应该足够好.

I suppose if you have var-length data and some rows are much larger than others then this approach may only be approximate but in most cases it should be good enough.

这篇关于SQL:获取表子集的物理大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆