--**************************************************************************************
--
-- Summary: Range partition tables CDR and CDR_AUX
-- - Creates partition function pfDaily on the End_Date column of the CDR table, so that each partition contains one day of data.
-- - Creates partition scheme pfDaily to map the partitions to filegroups. All partitions reside on the same filegroup (Primary).
-- - Drops and re-creates the CDR table specifying the partition scheme pfDaily as the location for the table.
-- - Creates partition function pfDaily_Aux on the End_Date column of the CDR_AUX table.
-- - Creates partition scheme pfDaily_Aux to map the partitions to filegroups. All partitions reside on the same filegroup (Primary).
-- - Drops and re-creates the CDR_AUX table specifying the partition scheme pfDaily_Aux as the location for the table.
--
--
-- SQL Server Version: 9.00
--
--**************************************************************************************
use AdventureWorks
go
--To drop all to re[eat the test remove the following lines
--truncate table cdr
--drop table cdr
--drop pARTITION SCHEME pfDaily
--drop partition function pfDaily;
--truncate table cdr_aux
--drop table cdr_aux
--drop pARTITION SCHEME pfDaily_aux
--drop partition function pfDaily_aux;
create partition function pfDaily (datetime)
as RANGE RIGHT for values(
'2005-05-07', '2005-05-08', '2005-05-09', '2005-05-10', '2005-05-11', '2005-05-12', '2005-05-13', '2005-05-14',
'2005-05-15', '2005-05-16', '2005-05-17', '2005-05-18', '2005-05-19', '2005-05-20', '2005-05-21', '2005-05-22',
'2005-05-23', '2005-05-24', '2005-05-25', '2005-05-26', '2005-05-27', '2005-05-28', '2005-05-29', '2005-05-30',
'2005-05-31', '2005-06-01', '2005-06-02', '2005-06-03', '2005-06-04', '2005-06-05', '2005-06-06', '2005-06-07',
'2005-06-08', '2005-06-09', '2005-06-10', '2005-06-11', '2005-06-12', '2005-06-13', '2005-06-14', '2005-06-15',
'2005-06-16', '2005-06-17', '2005-06-18', '2005-06-19', '2005-06-20', '2005-06-21', '2005-06-22', '2005-06-23',
'2005-06-24', '2005-06-25', '2005-06-26', '2005-06-27', '2005-06-28', '2005-06-29', '2005-06-30', '2005-07-01',
'2005-07-02', '2005-07-03', '2005-07-04')
go
-- This Partition MUST be on Left side, so the data MUST be the
-- day before of the first day.
create partition function pfDaily_Aux (datetime)
as RANGE RIGHT for values(
'2005-05-07',
'2005-05-08')
go
--Both partitions will be placed at the same FileGroup since the
--system is planned to run on SAN disk.
CREATE PARTITION SCHEME pfDaily as partition pfDaily all
to ([primary])
go
CREATE PARTITION SCHEME pfDaily_Aux as partition pfDaily_Aux all
to ([primary])
go
CREATE TABLE [dbo].[CDR] (
[ID_CDR] [int] NOT NULL ,
[Route] [int] NULL ,
[Direction] [tinyint] NULL ,
[IAM_Date] [datetime] NOT NULL ,
[ACM_Date] [datetime] NULL ,
[ANM_Date] [datetime] NULL ,
[REL_Date] [datetime] NULL ,
[RLC_Date] [datetime] NULL ,
[End_Date] [datetime] NOT NULL
) on pfDaily ([End_Date])
GO
CREATE CLUSTERED INDEX [IX_End_Date]
ON [dbo].[CDR]([End_Date]) ON pfDaily ([End_Date])
GO
ALTER TABLE [dbo].[CDR] WITH NOCHECK ADD
CONSTRAINT [PK_CDR] PRIMARY KEY NONCLUSTERED
(
[Id_CDR],
[End_Date]
) on pfDaily ([End_Date])
GO
CREATE TABLE [dbo].[CDR_AUX] (
[ID_CDR] [int] NOT NULL ,
[Route] [int] NULL ,
[Direction] [tinyint] NULL ,
[IAM_Date] [datetime] NOT NULL ,
[ACM_Date] [datetime] NULL ,
[ANM_Date] [datetime] NULL ,
[REL_Date] [datetime] NULL ,
[RLC_Date] [datetime] NULL ,
[End_Date] [datetime] NOT NULL
) on pfDaily_Aux ([End_Date])
GO
CREATE CLUSTERED INDEX [IX_End_Date]
ON [dbo].[CDR_AUX]([End_Date]) ON pfDaily_aux ([End_Date])
GO
ALTER TABLE [dbo].[CDR_AUX] WITH NOCHECK ADD
CONSTRAINT [PK_CDR_AUX] PRIMARY KEY NONCLUSTERED
(
[Id_CDR],
[End_Date]
) on pfDaily_aux ([End_Date])