日期:2014-05-17  浏览次数:20426 次

字符型分区
兄弟们,求助
我现在有张表要分区,分区函数不会弄,求帮助
首先字段是字符型,然后看起来是这个样子的 62d4deeb-a3f4-4ef1-a4dd-f52ef984385c,这东西如何划分边界

------解决方案--------------------
按首字符 分区吧
------解决方案--------------------
SQL code

CREATE PARTITION FUNCTION myRange (varchar(20))
AS RANGE RIGHT FOR VALUES ('B0001', 'C0001', 'D0001');
GO
CREATE PARTITION SCHEME myRange
AS PARTITION myRange
ALL TO ( [PRIMARY] );

CREATE TABLE Test (col1 INT IDENTITY(1,1), col2 varchar(20))
ON myRange (col2) ;
GO

INSERT INTO Test (col2) VALUES('A001')

INSERT INTO Test (col2) VALUES('B001')
INSERT INTO Test (col2) VALUES('B002')

INSERT INTO Test (col2) VALUES('C001')
INSERT INTO Test (col2) VALUES('C002')
INSERT INTO Test (col2) VALUES('C003')

INSERT INTO Test (col2) VALUES('D001')
INSERT INTO Test (col2) VALUES('D002')
INSERT INTO Test (col2) VALUES('D003')
INSERT INTO Test (col2) VALUES('D004')
GO

--查看各分区记录
SELECT $partition.myRange(o.col2)AS[Partition Number]
,min(o.col2) AS [Min ID]
,max(o.col2) AS [Max ID]
,count(*) AS [Rows In Partition]
FROM dbo.Test AS o
GROUP BY $partition.myRange(o.col2)
ORDER BY [Partition Number]