最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SQL server 2005的表分區(qū)

 更新時間:2006年12月23日 00:00:00   作者:  

下面來說下,在SQL SERVER 2005的表分區(qū)里,如何對已經(jīng)存在的有數(shù)據(jù)的表進行分區(qū),其實道理和之前在http://www.cnblogs.com/jackyrong/archive/2006/11/13/559354.html說到一樣,只不過交換下順序而已,下面依然用例子說明:
   依然在c盤的data2目錄下建立4個文件夾,用來做4個文件組,然后建立數(shù)據(jù)庫


use master
IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'Data Partition DB3')
DROP DATABASE [Data Partition DB3]
GO
CREATE DATABASE [Data Partition DB3]
ON PRIMARY
(NAME='Data Partition DB Primary FG3',
FILENAME=
'C:\Data2\Primary\Data Partition DB Primary FG3.mdf',
SIZE=5,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG1]
(NAME = 'Data Partition DB3 FG1',
FILENAME =
'C:\Data2\FG1\Data Partition DB3 FG1.ndf',
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG2]
(NAME = 'Data Partition DB3 FG2',
FILENAME =
'C:\Data2\FG2\Data Partition DB3 FG2.ndf',
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG3]
(NAME = 'Data Partition DB3 FG3',
FILENAME =
'C:\Data2\FG3\Data Partition DB3 FG3.ndf',
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG4]
(NAME = 'Data Partition DB3 FG4',
FILENAME =
'C:\Data2\FG4\Data Partition DB3 FG4.ndf',
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 )
然后建立一個數(shù)據(jù)表:
USE [Data Partition DB3]
go
CREATE TABLE MyTable
(ID INT NOT NULL,
Date DATETIME,
Cost money ) on [primary]
并建立一個索引
USE [Data Partition DB3]
go
CREATE UNIQUE CLUSTERED INDEX MyTable_IXC
ON MyTable(ID) on [PRIMARY]
接下來往表里增加數(shù)據(jù)
USE [Data Partition DB3]
go
declare @count int
set @count =-25
while @count <=100
begin
insert into MyTable select @count,getdate(),100.00
set @count=@count+1
end
set @count =101
while @count <=200
begin
insert into MyTable select @count,getdate(),200.00
set @count=@count+1
end
set @count =201
while @count <=300
begin
insert into MyTable select @count,getdate(),300.00
set @count=@count+1
end
set @count =301
while @count <=400
begin
insert into MyTable select @count,getdate(),400.00
set @count=@count+1
end
set @count =401
while @count <=800
begin
insert into MyTable select @count,getdate(),500.00
set @count=@count+1
end
此時查詢一下,可以看到數(shù)據(jù)都在一個表里select * from sys.partitions where object_name(object_id)='MyTable'

 我們再建立表分區(qū)函數(shù)use [Data Partition DB3]
GO
CREATE PARTITION FUNCTION [Data Partition Range](int)
AS RANGE LEFT FOR VALUES (100,200,300)
這里表明分區(qū)的原則是四個分區(qū),從負(fù)數(shù)到100,101-200,201-300,大于300
當(dāng)然,如果用right for values的話,就是從負(fù)數(shù)到99,100到199,200-299,和大于300

最后,把表分區(qū)函數(shù)應(yīng)用到文件組里
USE [Data Partition DB3]
go
CREATE PARTITION SCHEME [Data Partition Scheme]
AS PARTITION [Data Partition Range]
TO ([Data Partition DB3 FG1], [Data Partition DB3 FG2], [Data Partition DB3 FG3],[Data Partition DB3 FG4]);
把原來建立好的表,移動到這個表分區(qū)里
Drop index MyTable_IXC on MyTable with (Move To [Data Partition Scheme] (ID) )

最后看一看select * from sys.partitions where object_name(object_id)='MyTable'

可以看到,原來的表的數(shù)據(jù)被正確分拆到四個文件組里去了,實現(xiàn)了表分區(qū)

http://www.cnblogs.com/jackyrong/archive/2006/11/16/562514.html

相關(guān)文章

最新評論

泰来县| 浙江省| 望都县| 太原市| 望城县| 婺源县| 鄂州市| 保靖县| 遂平县| 龙海市| 富锦市| 丰台区| 万全县| 岑巩县| 南雄市| 荥经县| 吉林市| 沙湾县| 潜江市| 营口市| 荣昌县| 虹口区| 桃园县| 随州市| 呼图壁县| 汕尾市| 张北县| 晋中市| 兴业县| 贺州市| 六盘水市| 长汀县| 康定县| 新竹县| 潞城市| 嘉善县| 丹江口市| 思茅市| 栾城县| 井冈山市| 桃源县|