---Horizontal sub-Library expansion of 02.SQLServer performance optimization

Source: Internet
Author: User
Tags filegroup

Summary article: Http://www.cnblogs.com/dunitian/p/4822808.html#tsql

First introduction to the concept of filegroups: http://www.cnblogs.com/dunitian/p/5276431.html

Last time I said the other solution (http://www.cnblogs.com/dunitian/p/6041745.html), that is, did not say the level of the library, this time well said.

The first big data that was shared last time, just to demonstrate the level of the library

1. Simulating part of the data

2. After the index is created, it is possible to group by date

Roughly divided by the amount of data

Step on track


Gui Method:

3.0 Creating Filegroups

Adding files to a filegroup

Command operation:

ALTER DATABASE Bigdata_testinfo_partialdata ADD filegroup Info

ALTER DATABASE Bigdata_testinfo_partialdata Add file (name=n ' TestInfo2006 ', Filename=n ' G:\SQLData\BigData_ TESTINFO2006.NDF ') to filegroup Info

Note: BIGDATA_TESTINFO2006.NDF is created by the database itself and does not need to be created manually (some comrades manually created and then error ...). Uh, a little laugh and cry.)

Query look:select * from Sys.filegroups

Horizontal Division Walk: Generally on a few steps,1. Create a partition function 2. Create a partition scheme 3. Create a partitioned table

Gui method

Partition function

Partitioning scheme

Previous picture Some people may not understand, using PPT to draw a concept map :

Create a script

System Generation Script:

+ View Code?
1234567891011121314151617181920212223242526272829 use [BigData_TestInfo_PartialData]gobegin transactioncreate partition function [CreatedatePartitionFun](varchar(10)) as range right for values(N‘2006-01-01‘, N‘2007-01-01‘, N‘2009-01-01‘, N‘2012-01-01‘)create partition scheme [CreatedatePartitionScheme] as partition [CreatedatePartitionFun] TO ([Info], [Info], [Info], [Info], [primary])alter table [dbo].[Info] drop constraint [PK__Info__3214EC07B2FE10C8]alter table [dbo].[Info] add primary key nonclustered (    [Id] asc)with (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]set ansi_padding oncreate clustered index [ClusteredIndex_on_CreatedatePartitionScheme_636193166313125124] on [dbo].[Info](    [CreateDate])with (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [CreatedatePartitionScheme]([CreateDate])drop index [ClusteredIndex_on_CreatedatePartitionScheme_636193166313125124] on [dbo].[Info] commit transactiongo

Command mode creation ( based on the commands generated above)

Creating partition functions and schemas (scenarios)

create partition function Createdatepartitionfun (varchar) as range right for values (n ' 2006-01-01 ', n ' 2007-01-01 ', n ' 2009-01-01 ', N ' 2012-01-01 ')

Create partition scheme Createdatepartitionscheme as partition [Createdatepartitionfun] to ([info], [info], [info] ], [primary])

Create a partitioned table

When a table has not been created

tables have been created (this is basically the case)

Major two-step, change primary key to nonclustered index + create partitioned clustered index

ALTER TABLE Info DROP constraint pk__info__3214ec064b338648

ALTER TABLE INFO ADD constraint pk_info_id primary key nonclustered (Id ASC)

Create clustered index ix_info_createdate on Info (createdate) on Createdatepartitionscheme (CreateDate)

Test: basically evenly dispersed in the various files, production environment when you can put these files on each disk

Reference article:









---Horizontal sub-Library expansion of 02.SQLServer performance optimization

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.