- use master
- go
- create database Mydata
- on primary
- (
- Name=mydata,
- filename='E:/DB/mydata.mdf',
- size=10,
- maxsize=50,
- filegrowth=1
- )
- Log On
- (
- name = mydata_log,
- filename='E:/DB/mydata_log.ldf',
- size=10,
- maxsize=50,
- filegrowth=1
- )
- go
- USE master
- go
- alter database mydata
- add filegroup FG2
- USE master
- go
- alter database mydata
- add file
- (
- NAME=FG2,
- FILENAME='E:/DB/FG2.ndf',
- size=50,
- filegrowth=1
- )
- TO FILEGROUP FG2
- GO --建立数据文件
- USE MYDATA
- GO
- EXECUTE SP_HELPFILE
- use mydata
- go
- create PARTITION FUNCTION [MYfq](datetime)AS RANGE
- RIGHT FOR VALUES ('20081101') --建立分区函数
- use mydata
- go
- create partition scheme [Myfa] as partition [Myfq]to(FG1,FG2) --建立分区方案
- use Mydata
- go
- CREATE TABLE fqTable
- ([ID] [int] IDENTITY(1,1) NOT NULL,
- [named] [nvarchar](50) NULL,
- [intime] [datetime] default getdate() NOT NULL
- ) ON Myfa(intime)
- declare @i int
- set @i=1
- while(@i<1000)
- begin
- insert into fqTable(named) values('第一个批次')
- set @i=@i+1
- end --填充数据
- select *From jishu
- SELECT $partition.myfq(o.intime) --查看分区表应用
- AS [Partition Number]
- , min(o.intime) AS [Min SendDate]
- , max(o.intime) AS [Max SendDate]
- , count(*) AS [Rows In Partition]
- FROM dbo.fqTable AS o
- GROUP BY $partition.myfq(o.intime)
- ORDER BY [Partition Number]
- execute sp_help fqtable
SQL Server 2005利用分区对数据处理
最新推荐文章于 2022-09-02 17:10:18 发布