概念就很少說了,網上大把. sql
--分區函數的做用是告訴SQL Server,如何將數據進行分區,例如按時間,按年齡,按省.ide
--而分區方案的做用則是告訴SQL Server,將已分區的數據放在哪一個文件組中. 多個硬盤上分開選擇的文件組更好. 函數
一,用語句spa
建立,分區方案:3d
- CREATE PARTITION SCHEME YearCustomerFollow AS PARTITION
- YearCustomerFollowFunction TO([PRIMARY],[PRIMARY],[PRIMARY],[PRIMARY],[PRIMARY])
建立,分區函數:blog
- CREATE PARTITION FUNCTION YearCustomerFollowFunction(datetime)
- AS RANGE RIGHT FOR VALUES('20100101','20110101','20120101','20130101')
刪除一個分區:get
- ALTER PARTITION FUNCTION YearCustomerFollowFunction() MERGE RANGE ('20100101')
添加一個分區:string
- ALTER PARTITION SCHEME YearCustomerFollow NEXT USED [PRIMARY] -- 分區方案
- ALTER PARTITION FUNCTION YearCustomerFollowFunction() SPLIT RANGE ('20090101') -- 分界值
建立分區:(這裏的語句能夠用嚮導生成更方便)it
- USE [SQL_ZZW]
- GO
- BEGIN TRANSACTION
- CREATE CLUSTERED INDEX [ClusteredIndex_on_YearCustomerFollow_01] ON [dbo].[ZZW_test]
- (
- [birthyday]
- )WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [YearCustomerFollow]([birthyday])
- DROP INDEX [ClusteredIndex_on_YearCustomerFollow_01] ON [dbo].[ZZW_test] WITH ( ONLINE = OFF )
查詢分區錶行數.io
- select $PARTITION.YearCustomerFollowFunction(birthyday) as 分區編號,count(id) as 記錄數
- from zzw_test
- group by $PARTITION.YearCustomerFollowFunction(birthyday)
二,用嚮導
1,在要修改的表上右鍵->存儲->建立分區.
2,選擇分區列.
3,建立分區函數或選擇之後的分區函數.
4,建立分區方案或選擇現有分區方案.
5,映射分區,先設置邊界.
6,能夠看到邊界值都一會兒已經設置好了.
7,建立完成.
查看:表右鍵->存儲-管理壓縮.能夠看到各分區的行數,空間.
在控制檯庫->存儲下能夠直接看到剛建立的分區方案和分區函數.