Sqlserver表分區

use TestSplitDBsql

--先建立好數據庫
--1. 建立文件組
alter database TestSplitDB add filegroup testSplitGroup1
alter database TestSplitDB add filegroup testSplitGroup2
alter database TestSplitDB add filegroup testSplitGroup3
alter database TestSplitDB add filegroup testSplitGroup4
alter database TestSplitDB add filegroup testSplitGroup5數據庫

--2. 建立數據文件到文件組裏面
alter database TestSplitDB add file
(name=N'Test1',filename=N'F:\work\FA\FDC\DataBase\Test\Test1.ndf',size=5Mb,filegrowth=5mb)
to filegroup testSplitGroup1it

alter database TestSplitDB add file
(name=N'Test2',filename=N'F:\work\FA\FDC\DataBase\Test\Test2.ndf',size=5Mb,filegrowth=5mb)
to filegroup testSplitGroup2io


alter database TestSplitDB add file
(name=N'Test3',filename=N'F:\work\FA\FDC\DataBase\Test\Test3.ndf',size=5Mb,filegrowth=5mb)
to filegroup testSplitGroup3test


alter database TestSplitDB add file
(name=N'Test4',filename=N'F:\work\FA\FDC\DataBase\Test\Test4.ndf',size=5Mb,filegrowth=5mb)
to filegroup testSplitGroup4file


alter database TestSplitDB add file
(name=N'Test5',filename=N'F:\work\FA\FDC\DataBase\Test\Test5.ndf',size=5Mb,filegrowth=5mb)
to filegroup testSplitGroup5sql語句

--3. 右鍵到要分區的表--- >> 存儲 --- >> 建立分區 --- >>顯示嚮導視圖 --- >> 下一步 --- >> 下一步im

--假如你選擇的是int類型的列:那麼你的分區能夠指定爲1--100W是一個分區,100W--200W是一個分區....
--假如你選擇的是datatime類型:那麼你的分區能夠指定爲:2019-01-01--2019-01-31一個分區...
--根據這樣的列數據規則劃分,那麼在那個區間的數據,在插入數據庫時就被指向那個分區存儲下來
數據

 

 

最後:執行建立分區造成的sql語句:db

USE [TestSplitDB]
GO
BEGIN TRANSACTION
CREATE PARTITION FUNCTION [testfuction](bigint) AS RANGE LEFT FOR VALUES (N'100', N'200', N'300', N'400', N'500')


CREATE PARTITION SCHEME [testarea] AS PARTITION [testfuction] TO ([PRIMARY],
[testSplitGroup1], [testSplitGroup2], [testSplitGroup3], [testSplitGroup4], [testSplitGroup5])
go

CREATE CLUSTERED INDEX [ClusteredIndex_on_testarea_636905853491577240] ON [dbo].[Test]
(
[DateTime]
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [testarea]([DateTime])

DROP INDEX [ClusteredIndex_on_testarea_636905853491577240] ON [dbo].[Test] COMMIT TRANSACTION

相關文章
相關標籤/搜索