Finding table size (physical disk space) 
October 4th, 2007, 10:53 PM
| | Member | | Join Date: May 2007
Posts: 101
| | |
How do I find how much space a table takes up on a hard drive? Is there any call you can make that returns a size?
If so, how can I display this with asp?
Thanks for any help and insights.
| 
October 4th, 2007, 11:14 PM
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
Provided Answers: 1 | | | re: Finding table size (physical disk space)
Heya, Zensunni.
Check this out: -
SELECT
-
`DATA_LENGTH`
-
FROM
-
`information_schema`.`TABLES`
-
WHERE
-
(
-
`TABLE_SCHEMA` = 'database name'
-
AND
-
`TABLE_NAME` = 'table name'
-
)
-
LIMIT 1;
-
| 
October 5th, 2007, 05:18 AM
| | Member | | Join Date: May 2007
Posts: 101
| | | re: Finding table size (physical disk space)
Ops, I'm retarded.
I meant to post in the MS SQL forum. Thanks for the reply though. MySQL is my DB of choice. Just wish all my clients could think that too :)
Thanks again and sorry.
| 
October 5th, 2007, 01:11 PM
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
Provided Answers: 1 | | | re: Finding table size (physical disk space)
Heya, zensunni.
No problem.
I'm going to go ahead and move this thread to the MS SQL forum, where our resident Experts will be better able to help you out.
| 
October 11th, 2007, 11:02 PM
| | Member | | Join Date: May 2007
Posts: 101
| | | re: Finding table size (physical disk space)
I'm pretty sure it's one of the system tables I have to access, which holds the information, but I'm unsure of which one.
| 
October 12th, 2007, 01:22 AM
|  | Expert | | Join Date: Nov 2006
Posts: 1,017
| | | re: Finding table size (physical disk space)
Let's assume you want to find out space that is taken by sysobjects.
Usually to see space used by the table you execute following statement:
Because you need to query the same data I assume you are interested in reserved space by this table in a database. Use query below to select the same data directly from system tables. If you use SQL 2005 add schema name before system table name. - Declare @table varchar(50)
-
select @table = 'sysobjects'
-
-
select ltrim(str((select sum(reserved)
-
from sysindexes
-
where indid in (0, 1, 255)
-
and id = object_id(@table) )
-
* d.low / 1024.,15,0) +
-
' KB')
-
from master.dbo.spt_values d
-
where d.number = object_id(@table)
-
and d.type = 'E'
Good Luck.
Last edited by pbmods; October 12th, 2007 at 01:54 AM.
Reason: Changed [CODE] to [CODE=sql].
| 
October 30th, 2007, 10:20 PM
| | Member | | Join Date: May 2007
Posts: 101
| | | re: Finding table size (physical disk space)
Thanks all. I used these commands:
To find all the tables:
SELECT * FROM sysobjects WHERE type = 'U'
To find out how much space was used by a table:
exec sp_spaceused '<tablename>'
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|