Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 calculate 1 row size

Author  Topic 

imughal
Posting Yak Master

192 Posts

Posted - 2010-07-29 : 07:52:14
hi,

i have table with around 100 fields. i want to calculate 1 row size. pls tell how do i calculate it.

thx

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-29 : 14:55:50
you can use:

exec sp_spaceused MyTable
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-30 : 07:24:58
or try this:
select 
ps.database_id
,ps.object_id
,o.name
,o.type_desc
,ps.index_id
,b.name as index_name
,ps.avg_fragmentation_in_percent
,ps.avg_page_space_used_in_percent
,ps.avg_fragment_size_in_pages
,ps.fragment_count
,ps.page_count
,ps.record_count
,ps.index_type_desc
,ps.min_record_size_in_bytes
,ps.max_record_size_in_bytes
,ps.avg_record_size_in_bytes --in bytes
,ps.record_count*ps.avg_record_size_in_bytes as index_size_in_bytes
,(ps.record_count*ps.avg_record_size_in_bytes)/1024 as index_size_in_KiloBytes
,(ps.record_count*ps.avg_record_size_in_bytes)/1048576 as index_size_in_MegaBytes
,(ps.record_count*ps.avg_record_size_in_bytes)/1073741824 as index_size_in_GigaBytes
,ps.alloc_unit_type_desc
,ps.partition_number
,ps.index_level
,ps.index_depth
,b.fill_factor
,b.allow_row_locks
,b.allow_page_locks

from
sys.dm_db_index_physical_stats (7, 525960950, null, null, 'SAMPLED') as ps
inner join sys.indexes as b
on ps.object_id = b.object_id
and ps.index_id = b.index_id
inner join sys.all_objects as o
on o.object_id = ps.object_id

where ps.database_id = 7 --database ID
and b.object_id = 525960950 --table object ID
order by ps.object_id
Go to Top of Page
   

- Advertisement -