我试图在临时表上实现哈希分区。
以下是我执行的查询:
-- Adding the file group
ALTER DATABASE myDB
ADD FILEGROUP DistData;
GO
ALTER DATABASE myDB
ADD FILE
(
NAME = DistDatafile,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\DistDatafile.ndf',
SIZE = 5 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5MB
)
TO FILEGROUP DistData;
GO
CREATE PARTITION FUNCTION [Hashing] (TINYINT) AS RANGE LEFT FOR VALUES (0, 1, 2, 3, 4, 5, 6, 7)
CREATE PARTITION SCHEME [ps_Hashing] AS PARTITION [Hashing] ALL TO ([DistData])
-- Creating Temp Table #myTempTable and Copying the contents of myTable to it.
select *
into #myTempTable
from myTable
ALTER TABLE #myTempTable
ADD [HashValue] AS (CONVERT([tinyint], abs(binary_checksum(country)%(12)),(0)))
PERSISTED NOT NULL
-- ERROR WHILE DOING THIS
CREATE UNIQUE CLUSTERED INDEX [IX_Distribution]
ON #myTempTable
([REQ_SEQ] ASC, [HashValue])
ON [ps_Hashing](HashValue)
运行上述查询时出现错误:
消息1921,级别16,状态1,第29行,指定了无效的分区方案“ ps_Hashing”。
但是,如果我运行SELECT * FROM sys.partition_schemes WHERE name='ps_Hashing'
我可以看到该方案存在。