關於SQL Server的分割槽表
關於SQL Server資料分割槽技術是在SQL Server 2005的時候就引入的,這裡我只是想從測試的角度說明怎樣去檢查一個資料庫的分割槽是否正確.
我們可以利用下面的程式碼進行資料分割槽的檢查.
SELECT CONVERT( VARCHAR(16), PS.[name] )AS Partition_Scheme,
P.partition_number,
CONVERT( VARCHAR(10), DS2.[name])AS PartionFileGroup,
CONVERT( VARCHAR(19), COALESCE( V.[Value], '' )) AS Range_Boundry,
STR( P.Rows, 9 ) AS Rows
FROM sys.Indexes I
INNER JOIN sys.partition_schemes PS ON I.data_space_id = PS.data_space_id
INNER JOIN sys.destination_data_spaces DDS ON PS.data_space_id = DDS.partition_scheme_id
INNER JOIN sys.data_spaces DS2 ON DDS.data_space_id = DS2.data_space_id
INNER 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
INNER 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( 'PartitionTable' ) AND i.index_id = 0
ORDER BY P.partition_number
P.partition_number,
CONVERT( VARCHAR(10), DS2.[name])AS PartionFileGroup,
CONVERT( VARCHAR(19), COALESCE( V.[Value], '' )) AS Range_Boundry,
STR( P.Rows, 9 ) AS Rows
FROM sys.Indexes I
INNER JOIN sys.partition_schemes PS ON I.data_space_id = PS.data_space_id
INNER JOIN sys.destination_data_spaces DDS ON PS.data_space_id = DDS.partition_scheme_id
INNER JOIN sys.data_spaces DS2 ON DDS.data_space_id = DS2.data_space_id
INNER 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
INNER 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( 'PartitionTable' ) AND i.index_id = 0
ORDER BY P.partition_number
舉個例子:
--Creatinmg Partition Function
CREATE PARTITION FUNCTION PartiFunc( INT )
AS RANGE LEFT FOR VALUES
( 1, 10, 100, 1000, 10000, 100000, 1000000 )
CREATE PARTITION FUNCTION PartiFunc( INT )
AS RANGE LEFT FOR VALUES
( 1, 10, 100, 1000, 10000, 100000, 1000000 )
--Creatinmg Partition Scheme
CREATE PARTITION SCHEME PartiSche
AS PARTITION PartiFunc ALL TO ( [PRIMARY] )
CREATE PARTITION SCHEME PartiSche
AS PARTITION PartiFunc ALL TO ( [PRIMARY] )
--Creatinmg Partition Table
CREATE TABLE dbo.PartitionTable
( RowID INT IDENTITY(1, 1),
Number INT
)ON PartiSche ( RowID )
CREATE TABLE dbo.PartitionTable
( RowID INT IDENTITY(1, 1),
Number INT
)ON PartiSche ( RowID )
INSERT dbo.PartitionTable
( Number )
SELECT ROW_NUMBER() OVER( ORDER BY [name] ) AS RID
FROM sys.all_objects
( Number )
SELECT ROW_NUMBER() OVER( ORDER BY [name] ) AS RID
FROM sys.all_objects
--View of partiton Recrds
SELECT CONVERT( VARCHAR(16), PS.[name] )AS Partition_Scheme, P.partition_number,
CONVERT( VARCHAR(10), DS2.[name])AS PartionFileGroup,
CONVERT( VARCHAR(19), COALESCE( V.[Value], '' )) AS Range_Boundry,
STR( P.Rows, 9 ) AS Rows
FROM sys.Indexes I
INNER JOIN sys.partition_schemes PS ON I.data_space_id = PS.data_space_id
INNER JOIN sys.destination_data_spaces DDS ON PS.data_space_id = DDS.partition_scheme_id
INNER JOIN sys.data_spaces DS2 ON DDS.data_space_id = DS2.data_space_id
INNER 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
INNER 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( 'PartitionTable' ) AND
i.index_id = 0
ORDER BY P.partition_number
SELECT CONVERT( VARCHAR(16), PS.[name] )AS Partition_Scheme, P.partition_number,
CONVERT( VARCHAR(10), DS2.[name])AS PartionFileGroup,
CONVERT( VARCHAR(19), COALESCE( V.[Value], '' )) AS Range_Boundry,
STR( P.Rows, 9 ) AS Rows
FROM sys.Indexes I
INNER JOIN sys.partition_schemes PS ON I.data_space_id = PS.data_space_id
INNER JOIN sys.destination_data_spaces DDS ON PS.data_space_id = DDS.partition_scheme_id
INNER JOIN sys.data_spaces DS2 ON DDS.data_space_id = DS2.data_space_id
INNER 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
INNER 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( 'PartitionTable' ) AND
i.index_id = 0
ORDER BY P.partition_number
CREATE PARTITION FUNCTION myPartFn ( NUMERIC (18,2) ) AS RANGE LEFT FOR VALUES( 5000, 10000, 15000, 20000, 25000 )
/* <=5000, >5000 AND <=10000, >10000 AND <=15000, >15000 AND <=20000, >20000 AND <=25000, >25000 */
/* <=5000, >5000 AND <=10000, >10000 AND <=15000, >15000 AND <=20000, >20000 AND <=25000, >25000 */
--CREATE PARTITION FUNCTION myPartFn ( NUMERIC (18,2) ) AS RANGE RIGHT FOR VALUES( 5000, 10000, 15000, 20000, 25000 )
/* <5000, >=5000 AND <10000, >=10000 AND <15000, >=15000 AND <20000, >=20000 AND <25000, >=25000 */
/* <5000, >=5000 AND <10000, >=10000 AND <15000, >=15000 AND <20000, >=20000 AND <25000, >=25000 */
CREATE PARTITION SCHEME myPartSchm AS PARTITION myPartFn ALL TO ([PRIMARY])
SELECT * FROM sys.partition_functions; SELECT * FROM sys.partition_schemes;
CREATE TABLE dbo.myPartitionTable
( EmployeeID INT IDENTITY(1,1), SalaryAmt NUMERIC(18, 2) ) ON myPartSchm( SalaryAmt )
( EmployeeID INT IDENTITY(1,1), SalaryAmt NUMERIC(18, 2) ) ON myPartSchm( SalaryAmt )
CREATE CLUSTERED INDEX C_INDX_myPartitionTable_00001 ON dbo.myPartitionTable( EmployeeID )
CREATE NONCLUSTERED INDEX NC_INDX_myPartitionTable_00001 ON dbo.myPartitionTable( SalaryAmt )
CREATE NONCLUSTERED INDEX NC_INDX_myPartitionTable_00001 ON dbo.myPartitionTable( SalaryAmt )
SELECT * FROM sys.partitions WHERE [object_id] = OBJECT_ID(N'dbo.myPartitionTable')
INSERT INTO dbo.myPartitionTable( SalaryAmt )
SELECT 2000 UNION ALL SELECT 2500 UNION ALL SELECT 3000 UNION ALL SELECT 3500 UNION ALL SELECT 5000 UNION ALL
SELECT 6000 UNION ALL SELECT 7300 UNION ALL SELECT 7500 UNION ALL SELECT 9800 UNION ALL SELECT 8900 UNION ALL
SELECT 11000 UNION ALL SELECT 7890 UNION ALL SELECT 15200 UNION ALL SELECT 17500 UNION ALL SELECT 2500 UNION ALL
SELECT 25000 UNION ALL SELECT 78000 UNION ALL SELECT 65000 UNION ALL SELECT 22000 UNION ALL SELECT 20000
SELECT 2000 UNION ALL SELECT 2500 UNION ALL SELECT 3000 UNION ALL SELECT 3500 UNION ALL SELECT 5000 UNION ALL
SELECT 6000 UNION ALL SELECT 7300 UNION ALL SELECT 7500 UNION ALL SELECT 9800 UNION ALL SELECT 8900 UNION ALL
SELECT 11000 UNION ALL SELECT 7890 UNION ALL SELECT 15200 UNION ALL SELECT 17500 UNION ALL SELECT 2500 UNION ALL
SELECT 25000 UNION ALL SELECT 78000 UNION ALL SELECT 65000 UNION ALL SELECT 22000 UNION ALL SELECT 20000
SELECT * FROM dbo.myPartitionTable WHERE SalaryAmt <= 5000
SELECT * FROM sys.partitions WHERE [object_id] = OBJECT_ID(N'dbo.myPartitionTable')
DROP TABLE dbo.myPartitionTable
DROP PARTITION SCHEME myPartSchm
DROP PARTITION FUNCTION myPartFn
DROP PARTITION SCHEME myPartSchm
DROP PARTITION FUNCTION myPartFn
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14321372/viewspace-611393/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL Server表分割槽SQLServer
- SQL server 分割槽表SQLServer
- SQL SERVER之分割槽表SQLServer
- Sql Server系列:分割槽表操作SQLServer
- SQL Server表分割槽詳解SQLServer
- HGDB的分割槽表實現SQL Server的分割槽檢視SQLServer
- sql server 小記——分割槽表(上)SQLServer
- SQL Server表分割槽操作詳解SQLServer
- 關於分割槽表的操作
- sql server針對表增加新的分割槽SQLServer
- SQL Server 表分割槽注意事項HXSQLServer
- SQL SERVER 2005表分割槽功能SQLServer
- 關於分割槽表的move操作
- SQL Server大分割槽表沒有空分割槽的情況下如何擴充套件分割槽的方法SQLServer套件
- SQL Server表分割槽刪除詳情DSCCSQLServer
- SQL Server 2005分割槽表例項SQLServer
- SQL Server 表分割槽(partitioned table/Data Partitioning)SQLServer
- SqlServer關於分割槽表的總結SQLServer
- 關於分割槽表的概念及操作
- 關於分割槽表和分割槽索引(About Partitioned Tables and Indexes)索引Index
- mysql~關於mysql分割槽表的測試MySql
- 範圍分割槽表和INTERVAL分割槽表對於SPLIT分割槽的區別
- 關於修改分割槽表的問題總結
- SQL Server 2005 中的分割槽表和索引應用SQLServer索引
- SQL Server2005 表分割槽三步曲SQLServer
- oracle實用sql(14)--查詢分割槽表的分割槽列和子分割槽列OracleSQL
- 關於oracle的表空間,分割槽表,以及索引的總結Oracle索引
- 關於修改分割槽表的準備和操作細則
- 關於分割槽表中的全partition掃描問題
- 關於oracle的表空間,分割槽表,以及索引的總結(轉)Oracle索引
- 關於oracle的表空間,分割槽表,以及索引的總結 -- 轉Oracle索引
- Oracle 是分割槽表,但條件不帶分割槽條件的SQLOracleSQL
- 如何查詢分割槽表的分割槽及子分割槽
- Oracle SQL調優之分割槽表OracleSQL
- oracle分割槽表和分割槽表exchangeOracle
- rebuild分割槽表分割槽索引的方法Rebuild索引
- oracle關於分割槽相關操作Oracle
- 關於分割槽表Local索引Rebuild的一些總結索引Rebuild