標籤:style blog http color io ar for sp 檔案
先準備測試表
CREATE TABLE [dbo].[Employee] ( EmployeeNo INT IDENTITY(1,1) PRIMARY KEY, EmployeeName NVARCHAR(50) NULL);
插入一些資料
INSERT Employee DEFAULT VALUES;GO 10000UPDATE Employee set EmployeeName = ‘Employee ‘ + CONVERT(VARCHAR, EmployeeNo)
建立檔案組
建立檔案(為了效能,可以設定檔案Path分布在不同的磁碟分割上)
建立分區準備
選擇分區列
建立分區函數
建立分區架構
定義邊界值,分區,因為有5個邊界值,所以需6個分區
產生的指令檔(換句話說上面的步驟等同於下面的語句)
USE [TestingDB]GOBEGIN TRANSACTIONCREATE PARTITION FUNCTION [EmpFunction](int) AS RANGE RIGHT FOR VALUES (N‘2000‘, N‘4000‘, N‘6000‘, N‘8000‘, N‘10000‘)CREATE PARTITION SCHEME [FunScheme] AS PARTITION [EmpFunction] TO ([FileGroup1], [FileGroup2], [FileGroup3], [FileGroup4], [FileGroup5], [PRIMARY])ALTER TABLE [dbo].[Employee] DROP CONSTRAINT [PK__Employee__7AD0F1B633D4B598]ALTER TABLE [dbo].[Employee] ADD PRIMARY KEY CLUSTERED ( [EmployeeNo] 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 [FunScheme]([EmployeeNo])COMMIT TRANSACTION
執行上面的SQL語句
其中語句ON [FunScheme]([EmployeeNo])是關鍵,表明了表Employee依賴分區架構FunScheme來進行分區,分區的列為EmployeeNo
而分區架構有依賴於分區函數,即分區表依賴分區架構,分區架構又依賴於分區函數
查看錶分區結果
SQL Server 建立表分區