SQL2005分區表可以在一定程度上解決海量數據的性能問題,比如可以規避高訪問量數據區段的io競爭,可以縮小你查詢數據范圍的索引大小。 msdn參考
http://msdn.microsoft.com/zh-cn/library/ms345146.aspx 一個完整的腳本示例
--drop database dbPartitionTest
--測試數據庫
create database dbPartitionTest
go
use
dbPartitionTest
go
--增加分組
alter database dbPartitionTest ADD FILEGROUP P200801
alter database dbPartitionTest ADD FILEGROUP P200802
alter database dbPartitionTest ADD FILEGROUP P200803
go
--分區函數
CREATE PARTITION FUNCTION part_Year(datetime)
AS RANGE LEFT FOR VALUES
(
'20080131 23:59:59.997','20080229 23:59:59.997','20080331 23:59:59.997'
)
go
--增加文件組
ALTER DATABASE dbPartitionTest ADD FILE (NAME = N'P200801',FILENAME = N'c:\tb_P200801.ndf',SIZE = 1MB,MAXSIZE = 500MB,FILEGROWTH = 1MB)TO FILEGROUP P200801
ALTER DATABASE dbPartitionTest ADD FILE (NAME = N'P200802',FILENAME = N'c:\tb_P200802.ndf',SIZE = 1MB,MAXSIZE = 500MB,FILEGROWTH = 1MB)TO FILEGROUP P200802
ALTER DATABASE dbPartitionTest ADD FILE (NAME = N'P200803',FILENAME = N'c:\tb_P200803.ndf',SIZE = 1MB,MAXSIZE = 500MB,FILEGROWTH = 1MB)TO FILEGROUP P200803
go
--分區架構
CREATE PARTITION SCHEME part_YearScheme AS PARTITION part_Year TO (P200801,P200802,P200803,[PRIMARY])
go
CREATE TABLE [dbo].t_part
(name varchar(100) default newid(),date datetime NOT NULL)
ON part_YearScheme (date)
go
--添加測試數據,每天1條
declare @date datetime
set @date='2007-12-31'
while @date<='2008-04-01'
begin
insert into t_part(date)values(@date)
set @date=@date+1
end
go
--查詢數據分布在哪些分區
select $partition.part_Year(date) as 分區編號,* from t_part order by date
--查詢數據庫文件
go
sp_helpfile