最后得出结论,在sql2005中,单表的量最多不能超过200w数据。
而文章表和blog_vIEwcount这个表,我们现在采用2005得新特性,分区表来实现。事实上,反映还不错。以下写出创建分区表的步鄹(我们用blog_vIEwcount来做实例):
先根据表数据的量大小,来拆分每一个分区,保证分区之间在200w以下的数据 CREATE PARTITION FUNCTION OneYearDaterangePFN(datetime)
AS RANGE left FOR VALUES
(
'20070131 23:59:59.997',
'20070228 23:59:59.997',
'20070331 23:59:59.997',
'20070430 23:59:59.997',
'20070531 23:59:59.997',
'20070630 23:59:59.997',
'20070731 23:59:59.997',
'20070831 23:59:59.997',
'20070930 23:59:59.997',
'20071031 23:59:59.997',
'20071130 23:59:59.997',
'20071231 23:59:59.997'
)
然后我们需要添加相应的文件组
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200701 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200702 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200703 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200704 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200705 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200706 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200707 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200708 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200709 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200710 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200711 ]
ALTER DATABASE newcsdnblog ADD fileGROUP [ VIEwCount200712 ]
第三步,我们需要在服务器上建立出单独的文件(涉及到的朋友可能知道,我们如果把文件分布在不同的磁盘上,可以最大限度的提高磁头的读写能力;另:这里微软建议数据库服务器最好作RaID0 + RaID1)
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200701 ' ,filename = N ' f:SmalltableVIEwCount200701.ndf ' ,SIZE = 5MB,MAXSIZE = 100MB,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200701 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200702 ' ,filename = N ' f:SmalltableVIEwCount200702.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200702 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200703 ' ,filename = N ' f:SmalltableVIEwCount200703.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200703 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200704 ' ,filename = N ' f:SmalltableVIEwCount200704.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200704 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200705 ' ,filename = N ' f:SmalltableVIEwCount200705.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200705 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200706 ' ,filename = N ' f:SmalltableVIEwCount200706.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200706 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200707 ' ,filename = N ' f:SmalltableVIEwCount200707.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200707 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200708 ' ,filename = N ' f:SmalltableVIEwCount200708.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200708 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200709 ' ,filename = N ' f:SmalltableVIEwCount200709.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200709 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200710 ' ,filename = N ' f:SmalltableVIEwCount200710.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200710 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200711 ' ,filename = N ' f:SmalltableVIEwCount200711.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200711 ]
ALTER DATABASE newcsdnblog
ADD file
(name = N ' VIEwCount200712 ' ,filename = N ' f:SmalltableVIEwCount200712.ndf ' ,fileGROWTH = 5MB)
TO fileGROUP [ VIEwCount200712 ]
第四步,创建关联 CREATE PARTITION SCHEME OneYearDaterangePScheme
AS
PARTITION OneYearDaterangePFN
ALL TO ( [ PRIMARY ] )
第五步,创建表和索引(我这里只列出如何创建表)
CREATE table [ dbo ] . [ Blog_VIEwCount2 ]
(
[ EntryID ] [ int ] NOT NulL ,
[ BlogID ] [ int ] NOT NulL ,
[ VIEwDate ] [ datetime ] NOT NulL
)
ON OneYearDaterangePScheme (VIEwDate)
GO
如果大家希望查询此表中的相关数据,可以使用如下语句
select $partition.OneYearDaterangePFN(VIEwDate) from [ Blog_VIEwCount2 ] a order by a.VIEwDate asc 总结
以上是内存溢出为你收集整理的SQLServer 2005 海量数据解决方案 分区表全部内容,希望文章能够帮你解决SQLServer 2005 海量数据解决方案 分区表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)