SQLServer查看分區表詳細信息

SQL查看分區內記錄個數,常規方法須要知道分區函數而後再顯示,網上看到一個一句話顯示的方法數據庫

select convert(varchar(50), ps.name 

) as partition_scheme,
p.partition_number,
convert(varchar(10), ds2.name 

) as filegroup,
convert(varchar(19), isnull(v.value, ''), 120) as range_boundary,
str(p.rows, 9) as rows
from sys.indexes i
join sys.partition_schemes ps on i.data_space_id = ps.data_space_id
join sys.destination_data_spaces dds
on ps.data_space_id = dds.partition_scheme_id
join sys.data_spaces ds2 on dds.data_space_id = ds2.data_space_id
join sys.partitions p on dds.destination_id = p.partition_number
and p.object_id = i.object_id and p.index_id = i.index_id
join sys.partition_functions pf on ps.function_id = pf.function_id
LEFT JOIN sys.Partition_Range_values v on pf.function_id = v.function_id
and v.boundary_id = p.partition_number - pf.boundary_value_on_right
WHERE i.object_id = object_id('yourtablename')--分區表名
and i.index_id in (0, 1)
order by p.partition_number

版權聲明:本文爲CSDN博主「廟中和尚」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。函數

原文連接:https://blog.csdn.net/w2ndong/article/details/79494609spa

執行效果以下
.net

 其它方法日誌

select count(1) ,$PARTITION.WorkDatePFN(workdate) from imgfile group by $PARTITION.WorkDatePFN(workdate)
查看分區記錄數
select workdate ,$PARTITION.WorkDatePFN(workdate) from imgfile
查看記錄所在分區
 
dbcc shrinkfile(N'yxfile001',1)
收縮分區文件yxfile001爲1M
 
 
select * from sysfiles
查詢數據庫文件以及日誌文件的相關信息(文件組、當前文件大小、文件最大值、文件增加設置、文件邏輯名、文件路徑)
 
 
exec master.dbo.xp_fixeddrives
查詢各個磁盤分區的剩餘空間
 
 
exec sp_spaceused
查詢當前數據庫的磁盤使用狀況
 
 
select * from sys.partition_range_values
能夠查詢到分區號
相關文章
相關標籤/搜索