Partition Exchange as publishing technique in SQL Server?

会有一股神秘感。 提交于 2019-12-25 14:38:05

问题


I'm familiar with the concept of using partitions in Oracle as a technique to pubish incremental additions to tables (in a DW context).

(like this example)

For example. a daily snapshot for a data mart fact table is loaded behind the scenes in a partition within a table. for example with date as the partition key (1 partitioned table, with only one partition). once the load is complete, and the contents are validated, the partition can be 'exchanged' into the true destination table (1 partitioned table, with many partitions) as a dictionary event.

Is this same type of publishing model possible with SQL Server 2008?


回答1:


Table partitioning is available in the Developer and Enterprise editions of the SQL Server product and will enable you to do that process - to do it automated with stored procs etc is a bit harder but is achievable.




回答2:


Yes, and here is an example for SQL Server 2008 enterprise

Partition function by year 1:= Y < 2008, 2:= 2008, 3:= 2009, 4:= 2010, 5:= Y >= 2011

/* First create a partition function */
CREATE PARTITION FUNCTION myPFun (int)
AS RANGE RIGHT FOR VALUES (20080101, 20090101, 20100101, 20110101);
GO

Partition scheme to map ranges to file-groups. For this example I will map all partitions to the PRIMARY file group.

/* Then a partition scheme */
CREATE PARTITION SCHEME myPRng
AS PARTITION myPFun
ALL TO ( [PRIMARY] ); 
GO

And a fact table, partitioned by year

/* Fact table partitioned by year */
CREATE TABLE factTbl (DateKey int, Value int)
ON myPRng (DateKey) ;
GO

Staging table, partitioned the same way

/* Staging table partitioned the same way as the fact table */
CREATE TABLE stageTbl (DateKey int, Value int)
ON myPRng (DateKey) ;
GO

Some data to test

/* Populate fact table (years 2008, 2009)*/
INSERT  INTO factTbl
        ( DateKey, Value )
VALUES  ( 20080205, 10 )
,       ( 20080711, 25 )
,       ( 20090525, 43 );

/* Populate staging table (year 2010) */
INSERT  INTO stageTbl
        ( DateKey, Value )
VALUES  ( 20100107, 10 );

And switch the partition from the staging table to the fact table

/* From staging table to fact table */
ALTER TABLE stageTbl SWITCH PARTITION 4 TO factTbl PARTITION 4;
GO

To test

SELECT * FROM factTbl

Returns

DateKey     Value
----------- -----------
20080205    10
20080711    25
20090525    43
20100107    10

For more details see the msdn article.



来源:https://stackoverflow.com/questions/2011468/partition-exchange-as-publishing-technique-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!