The method of SQL normal table _mssql partition table

Source: Internet
Author: User

Copy Code code as follows:

CREATE TABLE Sale (
[ID] [int] identity (1,1) not NULL--automatic growth
[Name] [varchar] () not NULL,
[Saletime] [DateTime] Not NULL,
constraint [Pk_sale] PRIMARY key clustered--Create primary key
(
[Id] ASC
)
)
--Insert Some records
Insert Sale ([name],[saletime]) VALUES (' John ', ' 2009-1-1 ')
Insert Sale ([name],[saletime]) VALUES (' Dick ', ' 2009-2-1 ')
Insert Sale ([name],[saletime]) VALUES (' Harry ', ' 2009-3-1 ')
Insert Sale ([name],[saletime]) VALUES (' Money six ', ' 2010-4-1 ')
Insert Sale ([name],[saletime]) values (' Zhao Qi ', ' 2010-5-1 ')
Insert Sale ([name],[saletime]) VALUES (' John ', ' 2011-6-1 ')
Insert Sale ([name],[saletime]) VALUES (' Dick ', ' 2011-7-1 ')
Insert Sale ([name],[saletime]) VALUES (' Harry ', ' 2011-8-1 ')
Insert Sale ([name],[saletime]) VALUES (' Money six ', ' 2012-9-1 ')
Insert Sale ([name],[saletime]) values (' Zhao Qi ', ' 2012-10-1 ')
Insert Sale ([name],[saletime]) VALUES (' John ', ' 2012-11-1 ')
Insert Sale ([name],[saletime]) VALUES (' Dick ', ' 2013-12-1 ')
Insert Sale ([name],[saletime]) VALUES (' Harry ', ' 2014-12-1 ')


ALTER TABLE Sale DROP constraint Pk_sale
--Creates a primary key, but is not set to a clustered index
Alter TABLE Sale add constraint Pk_sale primary key nonclustered
(
[ID] ASC
) on [PRIMARY]


--Create partition functions
Go
create partition function [Pf_sale] (saletime) as range left for values (n ' 2010-5-1t00:00:00.000 ', n ' 2012-9-1t00:0 0:00.000 '
Go

--Create a partition structure
Go
create partition scheme [Pt_sale] as partition [Pf_sale] to ([Sale1], [Sale3], [Sale2])
Go

--Create a using [Pt_sale] Schema
Go
CREATE TABLE [dbo]. [Avcache] (
[ID] [int] identity (1,1) not NULL--automatic growth
[Name] [varchar] () not NULL,
[Saletime] [DateTime] Not NULL,
On [Pt_sale] (saletime)--note that the [Pt_sale] schema is used here, depending on the saletime partition

--View Usage
SELECT *, $PARTITION. [Pt_sale] (Saletime)
FROM dbo. [Avcache]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.