0

如何在未分區的表上創建分區索引,儘管存在分區函數和方案。這是一個excersise我讀的地方,而不是一個真正的問題非分區表上的分區索引

create partition function func(datetime) 
as range right for values 
('20040601', '20050601') 
go 
create partition scheme scheme1 
as partition func 
to ('primary') 
go 

create table student 
(
studentid int not null primary key nonclustered, 
firstname varchar(30) not null, 
date datetime not null 
) 

我在想

create clustered index IX_StudentID_Date 
on student(studentid, date) 

但該表沒有進行分配,因此,如何創建索引,未分割的表?

+0

請注意,在此過程中,您將創建所謂的非對齊索引(索引與表格分區不同),這會導致幾個問題(性能,無法使用SWITCH操作等)。你說這是一個練習,但在製作時要非常小心,不要做這樣的事情。 –

回答

1

當您對「表」進行分區時,實際上是對聚簇索引進行分區。所以分割非聚集索引其實是一樣的分區的「表」

CREATE NONCLUSTERED INDEX IX_StudentID_Date 
     ON student(studentid, date) 
     ON scheme1(date) 

你只需要確保分區字段是索引的一部分。