Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected fields from sp_spaceused query in mssql

Tags:

sql-server

For My query

exec sp_spaceused 'tablbename'

It returns

name | rows | reserved | data | index size | unused

But, I need only reserved field.

like image 638
BalaG Avatar asked Oct 21 '12 10:10

BalaG


People also ask

What is Sp_spaceused in SQL Server?

Displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.

How do you get space occupied by a table in SQL?

One simple way to do this is to use sp_spaceused to get the space used for a table.

What is total space reserved in SQL Server?

Reserved: The space reserved for use by database objects = (Data +Index + Unused) = 476704 + 1280 + 1312 = 479296 KB. This indicates how full the objects are; ideally, 10% of unused space is expected for transactional tables. Data: The actual size of the data. This is the sum of all the data files of the database.


1 Answers

Try this, but I hope there is a better way

DECLARE @spaceUsed TABLE (
    name varchar(255), 
    rows int, 
    reserved varchar(50), 
    data varchar(50), 
    index_size varchar(50), 
    unused varchar(50))

INSERT INTO @spaceUsed
exec sp_spaceused 'YOUR_TABLE'

SELECT reserved FROM @spaceUsed
like image 52
Kane Avatar answered Nov 15 '22 20:11

Kane