分享更有价值
被信任是一种快乐

SQL server 2005怎么实现表分区

文章页正文上

本篇内容介绍了“SQL server 2005怎么实现表分区”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
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 PRIMAR免费主机域名Y
(NAME=’Data Partition DB Primary FG3′,
FILENAME=
‘C:Data2PrimaryData Partition DB Primary FG3.mdf’,
SIZE=5,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG1]
(NAME = ‘Data Partition DB3 FG1’,
FILENAME =
‘C:Data2FG1Data Partition DB3 FG1.ndf’,
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG2]
(NAME = ‘Data Partition DB3 FG2’,
FILENAME =
‘C:Data2FG2Data Partition DB3 FG2.ndf’,
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROU免费主机域名P [Data Partition DB3 FG3]
(NAME = ‘Data Partition DB3 FG3’,
FILENAME =
‘C:Data2FG3Data Partition DB3 FG3.ndf’,
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 ),
FILEGROUP [Data Partition DB3 FG4]
(NAME = ‘Data Partition DB3 FG4’,
FILENAME =
‘C:Data2FG4Data Partition DB3 FG4.ndf’,
SIZE = 5MB,
MAXSIZE=500,
FILEGROWTH=1 )
然后建立一个数据表:
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]
接下来往表里增加数据
USE [Data Partition DB3]
go
declare @count int
set @count =-25
while @count begin
insert into MyTable select @count,getdate(),100.00
set @count=@count+1
end
set @count =101
while @count begin
insert into MyTable select @count,getdate(),200.00
set @count=@count+1
end
set @count =201
while @count begin
insert into MyTable select @count,getdate(),300.00
set @count=@count+1
end
set @count =301
while @count begin
insert into MyTable select @count,getdate(),400.00
set @count=@count+1
end
set @count =401
while @count begin
insert into MyTable select @count,getdate(),500.00
set @count=@count+1
end
此时查询一下,可以看到数据都在一个表里select * from sys.partitions where object_name(object_id)=’MyTable’

我们再建立表分区函数use [Data Partition DB3]
GO
CREATE PARTITION FUNCTION [Data Partition Range](int)
AS RANGE LEFT FOR VALUES (100,200,300)
这里表明分区的原则是四个分区,从负数到100,101-200,201-300,大于300
当然,如果用right for values的话,就是从负数到99,100到199,200-299,和大于300

最后,把表分区函数应用到文件组里
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]);
把原来建立好的表,移动到这个表分区里
Drop index MyTable_IXC on MyTable with (Move To [Data Partition Scheme] (ID) )

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

可以看到,原来的表的数据被正确分拆到四个文件组里去了,实现了表分区“SQL server 2005怎么实现表分区”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注云技术网站,小编将为大家输出更多高质量的实用文章!

相关推荐: sql之Oracle中匿名TABLE/VARRAY类型的示例分析

这篇文章将为大家详细讲解有关sql之Oracle中匿名TABLE/VARRAY类型的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。前言关于sql Oracle匿名TABLE/VARRAY类型的相关内容,在Oracle…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册