Question

I am new to SQL Server coding. Please let me know how to create a table with range partition on date in SQL Server

A similar syntax in teradata would be the following (a table is created with order date as range partition over year 2012 with each day as single partition )

CREATE TABLE ORDER_DATA (   
   ORDER_NUM INTEGER NOT NULL 
   ,CUST_NUM INTEGER 
   ,ORDER_DATE DATE 
   ,ORDER_TOT DECIMAL(10,2) 
) 
PRIMARY INDEX(ORDER_NUM) 
PARTITION BY (RANGE_N ( ORDER_DATE BETWEEN DATE ‘2012-01-01’ AND DATE 2012-12-31 EACH INTERVAL ‘1’ DAY)); 

Thanks in advance

Was it helpful?

Solution

The process of creating partitioned table is described on MSDN as follows:

Creating a partitioned table or index typically happens in four parts: 1. Create a filegroup or filegroups and corresponding files that will hold the partitions specified by the partition scheme. 2. Create a partition function that maps the rows of a table or index into partitions based on the values of a specified column. 3. Create a partition scheme that maps the partitions of a partitioned table or index to the new filegroups. 4. Create or modify a table or index and specify the partition scheme as the storage location.

You can find code samples on MSDN.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top