How to get the list of tables in a database and also the size of which each table occupies?

 Posted by Chvrsri on 12/23/2013 | Category: Sql Server Interview questions | Views: 4438 | Points: 40
Answer:

This is very intresting question where we need to understand on getting the complete list of tables in database is quite easy.

Syntax

USE SAMPLEDATABASE
SELECT * FROM SYS.TABLES

This query will return the complete list of tables in the selected Database.

Now coming to the second part by indentifying the total size of the table that it occupied. Here it is.

Syntax:
EXEC SP_USEDSPACE "Your Table Name goes here"

The above query will return number of rows in the table, Space reserved, actual space occupied and finally the free un-used space in the table.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Chvrsri on: 12/30/2013 | Points: 10
Thank you Sachin Jain
Posted by: Saranpselvam on: 4/8/2014 | Points: 10
EXEC SP_USEDSPACE this is not working in sqleserver 2008
Posted by: Saranpselvam on: 4/8/2014 | Points: 10
exec sp_spaceused this is correct one

Login to post response