How check size of table in SQL Server ?

It is topic about way to check information about size of object, example table or database,  and another information in SQL Server.

In SQL Server is sp_spaceused procedure  which show details about concrete object: disk space and number of rows in table or database.

First example obtains information about table Person from  AdventureWorks2012Test database.
If You current use master database as present screen below:
zz1You must use the database where is place table and call procedure with name of table with name of schema.

use AdventureWorks2012test;
GO
sp_spaceused [Person.Person];

Result:
zz2
————————————————————————————————————————————-

If You select this database in list:
zz3and execute this script:

use AdventureWorks2012test;
sp_spaceused [Person.Person];

You show this error:
Incorrect syntax near 'sp_spaceused'.

————————————————————————————————————————————-

But if You execute this code:

sp_spaceused [AdventureWorks2012test].[Person].[Person];

the error appear:
Incorrect syntax near '.'.

————————————————————————————————————————————-

You may correct this code above in this way:

sp_spaceused [AdventureWorks2012test.Person.Person];

Result:
zz2
————————————————————————————————————————————-

You may either check size of database , in this case You only set current database and don’t write name of object. It is example:

USE AdventureWorks2012test  
GO  
sp_spaceused;

Result:

zz4It is procedure so You may call it in all these examples above with adding EXEC word:

USE AdventureWorks2012test  
GO  
EXEC sp_spaceused;

 

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.