Cette requête permet d’obtenir l’ensemble des informations du partitionnement lorsque celui-ci est mis en Å“uvre dans une base.
SELECT pf.name AS PARTITION_FONCTION,
CASE pf.boundary_value_on_right
WHEN 0 THEN 'GAUCHE'
WHEN 1 THEN 'DROITE'
ELSE NULL
END AS VALEUR_BORNE,
ps.name as PARTITION_SCHEMA,
fg.name as STOCKAGE_FILEGROUP,
prv.value as VALEUR_BORNE,
CASE
WHEN dds.destination_id > pf.fanout
THEN 'OUI'
ELSE 'NON'
END AS RESERVE_STOCKAGE
FROM sys.partition_functions AS pf
LEFT OUTER JOIN sys.partition_schemes AS ps
ON pf.function_id= ps.function_id
LEFT OUTER JOIN sys.data_spaces AS ds
ON ps.data_space_id=ds.data_space_id
LEFT OUTER JOIN sys.destination_data_spaces AS dds
ON ps.data_space_id=dds.partition_scheme_id
LEFT OUTER JOIN sys.partition_range_values AS prv
ON pf.function_id=prv.function_id
AND dds.destination_id = CASE pf.boundary_value_on_right
WHEN 0 THEN prv.boundary_id
ELSE prv.boundary_id+1
END
LEFT OUTER JOIN sys.filegroups fg
ON dds.data_space_id=fg.data_space_id
--------
Frédéric Brouard, SQLpro - ARCHITECTE DE DONNÉES, http://sqlpro.developpez.com/
Expert bases de données relationnelles et langage SQL. MVP Microsoft SQL Server
www.sqlspot.com : modélisation, conseil, audit, optimisation, tuning, formation
* * * * * Enseignant CNAM PACA - ISEN Toulon - CESI Aix en Provence * * * * *