如何获取SQL
Server数据库里表的占用容量大小?
其实只要使用系统内置的存储过程sp_spaceused就可以得到表的相关信息
如:sp_spaceused
'tablename'
step
1:先写一个存储过程,把当前的所有表的相关信息全部都保存在一个指定的表里面
CREATE
PROCEDURE
get_tableinfo
AS
if
not
exists
(select
*
from
dbo.sysobjects
where
id
=
object_id(N'[dbo].[tablespaceinfo]')
and
OBJECTPROPERTY(id,
N'IsUserTable')
=
1)
create
table
tablespaceinfo
--创建结果存储表
(nameinfo
varchar(50)
,
rowsinfo
int
,
reserved
varchar(20)
,
datainfo
varchar(20)
,
index_size
varchar(20)
,
unused
varchar(20)
)
delete
from
tablespaceinfo
--清空数据表
declare
@tablename
varchar(255)
--表名称
declare
@cmdsql
varchar(500)
DECLARE
Info_cursor
CURSOR
FOR
select
o.name
from
dbo.sysobjects
o
where
OBJECTPROPERTY(o.id,
N'IsTable')
=
1
and
o.name
not
like
N'#%%'
order
by
o.name
OPEN
Info_cursor
FETCH
NEXT
FROM
Info_cursor
INTO
@tablename
WHILE
@@FETCH_STATUS
=
0
BEGIN
if
exists
(select
*
from
dbo.sysobjects
where
id
=
object_id(@tablename)
and
OBJECTPROPERTY(id,
N'IsUserTable')
=
1)
execute
sp_executesql
N'insert
into
tablespaceinfo
exec
sp_spaceused
@tbname',
N'@tbname
varchar(255)',
@tbname
=
@tablename
FETCH
NEXT
FROM
Info_cursor
INTO
@tablename
END
CLOSE
Info_cursor
DEALLOCATE
Info_cursor
GO
step
2:执行存储过程
exec
get_tableinfo
查询运行该存储过程后得到的结果
select
*
from
tablespaceinfo
order
by
cast(left(ltrim(rtrim(reserved))
,
len(ltrim(rtrim(reserved)))-2)
as
int)
desc
分享到:
相关推荐
before exploring schema and query optimization, tuning of parameters and how to get the best out of the latest innovations in hardware design. The Guide concludes with recent performance benchmarks ...
The estimation of total population size for various phenomena of crime is an important factor critical for criminal justice policy formulation and criminological theory development. In this paper, ...
Conclusion: Both the inconsistency in density and log level and the convergence of context have forced us to question whether it is a reliable means to understand the runtime behavior of software ...
Each CSS chapter comes with an end-of-chapter exercise where you get to practice the different CSS properties covered in the chapter and see first hand how different CSS values affect the design of ...
Each section describes how to interpret results and express them in a research report after the data are analyzed. For example, students are shown how to phrase the results of a significant and an ...
George Polya revealed how the mathematical method of demonstrating a proof or finding an unknown can be of help in attacking any problem that can be "reasoned" out - from building a bridge to winning...
Step Relational Database DesignTM bridges the gaps between database theory, database modeling, and database implementation by outlining a simple but reliable six-step process for accurately modeling ...
Description: This application demonstrates how to get the window title of an application you started with the shell command. Once you have the Window title you are able to detect the name of the ...
How to Create a Database in Python using SQL Lite 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How does one look at any organization and begin the work of automating it in sensible ways? This book provides the blueprint for automating critical business functions of all kinds. It outlines the ...
You′ll learn how to work with Positionable CSS to create floating elements, margins, and multi–column layouts, and you′ll get up to speed on client–side programming with JavaScript. You′ll also ...
In order to truly master JavaScript, you need to learn how to work effectively with the language’s flexible, expressive features and how to avoid its pitfalls. No matter how long you’ve been writing...
The number of levels in an index will vary depending on the number of rows in the table and the size of the key column or columns for the index. If you create an index using a large key, fewer ...
33. What has to be considered when using liveCache in SAP HANA environments? 34. Where can I find an overview of SAP HANA ...50. How can the historic growth of the SAP HANA database be determined?
One of the highlights of Gamesalad is that you DO NOT need to learn how to write traditional computer programming code to make your games. Gamesalad offers a simple, yet full-featured, drag and drop ...
A special feature of this edition is a new appendix on NoSQL and relational theory.Could you write an SQL query to find employees who have worked at least once in every programming department in the ...
Learn how to define strategies for cloud adoption of your Oracle database landscape. Understand private cloud, public cloud, and hybrid cloud computing in order to successfully design and manage ...
This one–of–a–kind guide includes a step–by–step action plan for harnessing the power of the Internet to create compelling messages, get them in front of customers, and lead those customers into...