| Author |
Topic |
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2010-07-28 : 08:52:37
|
| How can I get the number of rows per parition for a database without having to do a count?This gets the row count for all partitions per table, but not each individual partition:SELECT OBJECT_NAME(object_id), [rows] FROM sys.partitions pWHERE index_id = 0ThanksHearty head pats |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-07-28 : 10:46:44
|
| [code]SELECT t.name [table], p.rowsFROM sys.tables tJOIN sys.partitions pOn p.object_id = t.object_idWHERE is_ms_shipped = 0order by [table][/code] |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2010-07-28 : 11:23:03
|
Thanks Russell Hearty head pats |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-07-28 : 11:29:34
|
You're welcome |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2010-07-28 : 11:52:44
|
hey russellI don't suppose you know how to return the boundary value for the partitions as well?I have to leave now, but I'll thank you later BexHearty head pats |
 |
|
|
parody
Posting Yak Master
111 Posts |
Posted - 2010-07-29 : 05:01:16
|
| sys.dm_db_partition_stats also contains this info.Have a look at sys.partition_range_values for boundry values of the function.I think these are all the system views available:sys.partition_range_valuessys.partition_functionssys.partitionssys.partition_parameterssys.partition_schemessys.dm_db_partition_stats |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2010-07-29 : 09:05:50
|
Hi ParodyThanks for getting back to me.I've played around with the various system views, and have developed the following query. I have made an assumption, however, that the partition_number in sys.partition is the same as the boundary_id in sys.partition_range_values.Is this a correct assumption?SELECT t.name [table], p.rows, p.partition_number, v.boundary_id, v.valueFROM sys.tables tJOIN sys.partitions pOn p.object_id = t.object_idINNER JOIN sys.partition_range_values v ON v.boundary_id = p.partition_number WHERE is_ms_shipped = 0order by [table] BexHearty head pats |
 |
|
|
parody
Posting Yak Master
111 Posts |
Posted - 2010-07-29 : 09:47:35
|
| Hmm almost, you would always have a 6th partition to the right of the 5th boundry ID (i.e. you cut an apple 5 times you hev 6 pieces).so you would need to left join. Also remember your boundry definition of right and left defining which partition an on boundry value will fall. This is the boundry_value_on_right column in sys.partition_functions (a 1/0 - so 1 is right 0 is left) |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2010-07-29 : 10:04:19
|
| Cool, that makes sense.Thanks for your help!!Hearty head pats |
 |
|
|
|