首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>SQL server>资讯:使用SQL Server 2008实现可调窗口应用

使用SQL Server 2008实现可调窗口应用

www.jz123.cn  2009-12-25   来源:         我要投递新闻

在此练习中,您将实现一个可调窗口应用场景,通过将分区切换入表中以及从表中将分区切换出去实现此应用场景。在大多数系统中,最常使用的数据都是最新的数据。在非常大的表中,定期对时间最早的数据进行存档很有用,这样可以改善性能,对给新数据创建空间也是很有必要的。使用 SQL Server 2008 中分区表的 SPLIT、SWITCH 和 MERGE 功能,您可以极快地执行存档任务。

  注意: 您可以复制此练习中所用的脚本,这些脚本位于 C:SQLHOLSPartitioningSolutionPartition Processing 文件夹中的 Partition Processing.ssmssln 解决方案中。

  1.为存档表创建分区函数

  (1)在解决方案资源管理器中,右键单击该连接,然后单击新建查询。

  (2)右键单击 SQLQuery1.sql,然后单击重命名。

  (3)键入 Create Archive Partition Function.sql,然后按 Enter。

  (4)键入下面的代码。

  USE AdventureWorksDW

  
CREATE PARTITION FUNCTION pf_OrderDateKeyArchive(int)

  
AS RANGE RIGHT

  
FOR VALUES(185)

  
GO

 

  5.单击执行。

  2.为存档表创建分区方案

  (1)在解决方案资源管理器中,右键单击该连接,然后单击新建查询。

  (2)右键单击 SQLQuery1.sql,然后单击重命名。

  (3)键入 Create Archive Partition Scheme.sql,然后按 Enter。

  (4)键入下面的代码。

  USE AdventureWorksDW

  
CREATE PARTITION SCHEME ps_OrderDateKeyArchive

  
AS PARTITION pf_OrderDateKeyArchive

  
TO (fg2001,fg2002,fg2003)

  
GO

 

  (5)单击执行。

  3.为存档数据创建分区表

  (1)在解决方案资源管理器中,右键单击该连接,然后单击新建查询。

  (2)右键单击 SQLQuery1.sql,然后单击重命名。

  (3)键入 Create Archive Table.sql,然后按 Enter。

  (4)键入下面的代码。

  USE AdventureWorksDW

  
CREATE TABLE [dbo].[FactInternetSalesArchive]

  (

  
[InternetSalesID] [int] IDENTITY(1,1) NOT NULL,

  
[ProductKey] [int] NOT NULL,

  
[OrderDateKey] [int] NOT NULL,

  
[DueDateKey] [int] NOT NULL,

  
[ShipDateKey] [int] NOT NULL,

  
[CustomerKey] [int] NOT NULL,

  
[PromotionKey] [int] NOT NULL,

  
[CurrencyKey] [int] NOT NULL,

  
[SalesTerritoryKey] [int] NOT NULL,

  
[SalesOrderNumber] [nvarchar](20) NOT NULL,

  
[OrderQuantity] [smallint] NULL,

  
[UnitPrice] [money] NULL,

  
CONSTRAINT [PK_ FactInternetSalesArchive] PRIMARY KEY CLUSTERED

  (

  
[InternetSalesID],

  
[ProductKey],

  
[OrderDateKey],

  
[DueDateKey],

  
[ShipDateKey],

  
[CustomerKey],

  
[PromotionKey],

  
[CurrencyKey],

  
[SalesTerritoryKey]

  )

  )

  
ON ps_OrderDateKeyArchive(OrderDateKey)

  
GO

 

  (5)单击执行。

上一篇:如何应对锁住的数据记录:NOLOCK和READPAST 下一篇:详解SQL Server 2008滑动窗口的管理

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图