This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.
The purpose of the PartitioningScript sample is to demonstrate the table and index partitioning capabilities of SQL Server. For information about this feature, see "Partitioned Tables and Indexes" in SQL Server Books Online.
| Important: |
| Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. Sample applications should not be connected to or used with your production SQL Server database without the permission of the system administrator. |
In the AdventureWorks
sample database, the TransactionHistory
table is used to record each sales order, purchase order, and work order transaction. Therefore, this table is one of the largest and most heavily accessed tables in the database. The TransactionHistoryArchive
table was created to store older transactions from the TransactionHistory
table. Data is transferred to TransactionHistoryArchive
on a monthly basis for additional analysis enabling TransactionHistory
to stay reasonably small and maintain current data only.
To create the partitions for these tables, the sample performs these operations:
- Creates partition function TransactionRangePF1 on the TransactionDate column of the TransactionHistory table, so that each partition contains one month of data.
- Creates partition scheme TransactionsPS1 to map the partitions to filegroups. In this sample, all partitions reside on the same filegroup.
- Drops and re-creates the TransactionHistory table specifying the partition scheme TransactionsPS1 as the location for the table.
- Creates partition function TransactionRangePF2 on the TransactionDate column of the TransactionHistoryArchive table.
- Creates partition scheme TransactionsPS2 to map the partitions to filegroups. In this sample, all partitions reside on the same filegroup.
- Drops and re-creates the TransactionHistoryArchive table specifying the partition scheme TransactionsPS2 as the location for the table.
- Bulk inserts data into the two tables. The transfer of monthly "chunks" of data between the tables is performed by switching partitions between the two tables. This typically takes just seconds, instead of minutes or hours in earlier releases, because it is a metadata operation only instead of a physical relocation of the data. Partition switching is demonstrated in the SlidingWindow sample.
Before you run this sample, perform the following tasks:
Running the Sample
The following procedure shows how to run the PartitioningScript sample.
To run the PartitioningScript sample
- In SQL Server Management Studio, open the file PartitionAW.sql. The default installation directory is C:\Program Files\Microsoft SQL Server\100\Samples\Engine\\Administration\Partitioning\Scripts. Click Execute. © 2008 Microsoft Corporation. All rights reserved.