Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Table size in statistical database

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Use testdb

Go

If object_id ('tempdb.dbo.#tablespaceinfo','U') is not null

Drop table # tablespaceinfo

Create table # tablespaceinfo (

Nameinfo varchar (555)

Rowsinfo bigint

Reserved varchar (255)

Datainfo varchar (255)

Index_size varchar (255)

Unused varchar (255)

)

DECLARE @ tablename varchar

DECLARE Info_cursor CURSOR FOR

SELECT [name] FROM sys.tables WHERE type='U'

OPEN Info_cursor

FETCH NEXT FROM Info_cursor INTO @ tablename

WHILE @ @ FETCH_STATUS = 0

BEGIN

Insert into # tablespaceinfo exec sp_spaceused @ tablename

FETCH NEXT FROM Info_cursor

INTO @ tablename

END

CLOSE Info_cursor

DEALLOCATE Info_cursor

If object_id ('tempdb.dbo.#tab','U') is not null

Drop table # tab

SELECT

Nameinfo

, rowsinfo

, cast (replace (reserved,' KB','') as bigint) / 1024 "reserved (MB)"

, cast (replace (datainfo,' KB','') as bigint) / 1024 "datainfo (MB)"

, cast (replace (index_size,' KB','') as bigint) / 1024 "index_size (MB)"

, cast (replace (unused,' KB','') as bigint) / 1024 "unused (MB)"

Into # tab

FROM # tablespaceinfo

ORDER BY Cast (Replace (reserved,'KB','') as INT) DESC

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report