SQL Server Partitioning can be a bit confusing and can lead some companies in a different direction as far as archiving data. Writing the T-SQL code to create partition functions, partition schemes, and then altering the table to use the partition can be overwhelming for some DBA’s. SQL Server 2008 introduced a table partitioning wizard in SQL Server Management Studio that helps make this task easier. In this post, I’ll show you how to use this wizard. Let’s jump in.
Based on my experience, it seems as if SQL Server table partitioning is not commonly used and I’m not sure if it’s because of the complexity and management of partitions or if companies simply don’t have the knowledge of partitioning data. This tip will focus on the SQL Server Partitioning wizard as opposed to the ins and outs of partitioning.
To start the wizard, right click on the table you want to partition in SQL Server Management Studio and select Storage, Create Partition. In this example, I’m using AdventureWorks2012.Production.TransactionHistory.
On the Select a Partitioning Column screen as shown below you will need to select the column that you want to use to partition your table. The most common column used is a date column since most tables are being archived by date. In this example, I’ll choose TransactionDate so I’ll partition my table based on the date when the transaction was entered into this table.
Other options include:
Collocate this table to the selected partition table: Displays related data to join with the column being partitioned.
Storage Align Non Unique Indexes and Unique Indexes with an Indexed Partition Column: Aligns all indexes of the table being partitioned with the same partition scheme. If you do not select this option, you may place indexes independently of the columns they point to.
The next screen, Select a Partition Function, is where you will create the partition function. This will create a function that maps the rows of the table or index into partitions based on the values of the TransactionDate column. In this example, I’ll name the function TransactionHistoryFunction.
The next screen, Select a Partition Scheme, is where you will create the partition scheme. This will create a scheme that maps the partitions of the Production.TransactionHistory table to different filegroups. In this example, I’ll name the scheme TransactionHistoryScheme.