在sqlserver2000中使用分区表和分区视图

          在sqlserver2000中使用分区表和分区视图

用分区表和分区视图有什么好处,这里就不多说了.顺便说一句就是2000中的分区表和分区视图是伪分区,在2005中才实现了真正高性能的分区表.

diary表太大了,查询起来很慢,假如diary表有200多W数据.

1/建立分区表:
将diary表分离成5个表:
diary1/diary2/diary3/diary4/diary5,50万用户一个表.
select * into diary1 from diary where diary_id between 1 and 500000;
.
.
select * into diary1 from diary where diary_id between 1500001 and 2000000;
select * into diary1 from diary where diary_id >2000000;
--其实就是把一张表在物理上分成了5个.
2/建立分区视图:
CREATE VIEW diaryview
AS
SELECT * FROM diary1
UNION ALL
SELECT * FROM diary2
UNION ALL
SELECT * FROM diary3
UNION ALL
SELECT * FROM diary4
UNION ALL
SELECT * FROM diary5

然后当用户查询时,只给他们使用视图的权限,这样对于他们来说,就还和一张表一样了.
 

你可能感兴趣的:(sqlserver)