TheLittleSeeker
MIS
Hi Experts,
I'm using Ms SQL Server 2008 R2 (Enterprise edition), I need some help in compiling
the correct SQL query to check table size of certain tables.
There are plenty of examples from forums on checking for all tables, however, this
is not what I'm looking for.
Let's say I've the following tables: EMP001, EMP002, EMP003, EMP004, EMP005 in
database schema called: QUE.
Here are some examples that I've found which is what I would like to have it on my
SQL coding:
Is this the right way of doing so?
The above SQL coding is only checking for 1 table, how can it check for multiple
tables, 5 tables?
Could you help how can I make this coding working?
I've tried doing it several times on my own, but could not figure it out so far.
Thank you for your help.
I'm using Ms SQL Server 2008 R2 (Enterprise edition), I need some help in compiling
the correct SQL query to check table size of certain tables.
There are plenty of examples from forums on checking for all tables, however, this
is not what I'm looking for.
Let's say I've the following tables: EMP001, EMP002, EMP003, EMP004, EMP005 in
database schema called: QUE.
Here are some examples that I've found which is what I would like to have it on my
SQL coding:
Code:
declare @TableSpace table (TableName sysname, RowsK varchar(32), ReservedMB
varchar(32), DataMB varchar(32), IndexSizeMB varchar(32), UnusedMB varchar(32))
insert @TableSpace
exec sp_MSforeachtable @command1="exec sp_spaceused 'QUE.EMP001';"
update @TableSpace set RowsK = CONVERT(varchar, 1+convert(int, RowsK)/1024)
update @TableSpace set ReservedMB = CONVERT(varchar, 1+convert(int,LEFT(ReservedMB,
charindex(' K', ReservedMB,-1)))/1024)
update @TableSpace set DataMB = CONVERT(varchar, 1+convert(int,LEFT(DataMB,
charindex(' K', DataMB,-1)))/1024)
update @TableSpace set IndexSizeMB = CONVERT(varchar, convert(int,LEFT(IndexSizeMB,
charindex(' K', IndexSizeMB,-1)))/1024)
update @TableSpace set UnusedMB = CONVERT(varchar, convert(int,LEFT(UnusedMB,
charindex(' K', UnusedMB,-1)))/1024)
select * from @TableSpace order by convert(int,DataMB) desc
go
Is this the right way of doing so?
The above SQL coding is only checking for 1 table, how can it check for multiple
tables, 5 tables?
Could you help how can I make this coding working?
I've tried doing it several times on my own, but could not figure it out so far.
Thank you for your help.