How to create a partitioned index on a table which is not partitioned although there is a partition function and scheme available. It is an exercise I read somewhere, not a real problem
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
)
i was thinking of
create clustered index IX_StudentID_Date
on student(studentid, date)
but the table is not partitioned, so how to create the index, without partitioning the table?
When you partition the "table" you are actually partitioning the clustered index. So partitioning a non clustered index is actually the same as partitioning a "table"
CREATE NONCLUSTERED INDEX IX_StudentID_Date
ON student(studentid, date)
ON scheme1(date)
you just have to make sure that the partition field is part of the index.