<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Microsoft SQL Server Inside Out</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/hanspo/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/hanspo/feed.xml</link>
    <description>In this series of blog posts I&amp;#039;ll present my experiences gained in 15 years of supporting of SQL Server at Microsoft.
SQL Server Books Online is a great resource for reference material, but sometimes prooves akward for getting a fast start on a new fe</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:39:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>It's never too late for Partitioning your Tables</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/its-never-too-late-for-partitioning-your-tables</link>
      <pubDate>Tue, 23 May 2017 15:45:14 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/?p=65</guid>
      <description><![CDATA[Only a few developers design their tables for partitioning from ground up, simply because they do...]]></description>
      <content:encoded><![CDATA[Only a few developers design their tables for partitioning from ground up, simply because they do not envision that a table once might become so big that partitioning would become a real advantage. And even if they do, the fact that partitioning is an Enterprise-only feature (at least until SQL 2016 SP1) keeps them away from using it.

Recently, I was involved in a customer case where they did have an audit table where around 10 events were logged per second, all day long. That makes for a little less than 1 Mio. entries per day. And there was the need for a retention period of 30 days. So, once every day they had to delete about 1 Mio. entries from this 30 Mio. row table. This daily delete job was a constant blocker for all other transactions trying to insert into this table during the delete due to the exclusive table lock that was held on the table by the delete job. Not to mention the huge amount of data added to the transaction log with each delete.

Since the customer was running on Enterprise Edition, the obvious solution was to partition the table by day. Hence, the daily delete job would be replaced by a job that switches the oldest partition out into an archive table, merging the last partition, and deleting the archive table (since this was on SQL 2014, the new TRUNCATE TABLE WITH PARTITIONS wasn’t yet available). But partitioning the existing table by rebuilding the clustered index would require a maintenance window of several minutes. A price, the customer was not willing to pay. At least, not without evaluating alternatives.

So, I came up with a solution that partitions the table within milliseconds and without any major disruption for the transactions running in parallel. You think, that’s impossible? Stay tuned!

The crucial point is to dismiss the idea of partitioning the existing data and instead just partition all forthcoming data. I.e. all existing data go into one big partition, whereas all new data go into a new partition that is added every day. It's important that all indexes are already conformant with partition aligned indexes, i.e. the clustered index and all unique indexes must contain the partitioning column as a key column. In our case, the table only had a clustered index on the column that we intended to partition the table with. Hence, all requirements were already met.

We started with a partition layout consisting of 3 range right partitions. The left most partition was intentionally left empty, to allow for painless partition merging. The middle partition would store all rows that currently exist in the non-partitioned table. And starting by the next day, all new rows would go into the right most partition. From then on, each new day the customer would expand the partition layout by one new partition until they would have reached the final layout of 30 data partitions. At that point, they would start dropping the oldest partition each day, starting with the big partition we created right at the beginning.
<h3><strong>How to code this solution</strong></h3>
In the following I’ll outline the steps to be performed for partitioning the table with name <strong>AuditTab</strong> by the column <strong>create_date</strong> of type datetime2.

Let’s start with creating the partition function and scheme to be used for partitioning our table. First, we must determine the date of the oldest entry in our table. Although, not necessary, we round it down to 00:00 of that day (we want all boundary values of our partition function to be just dates without any time portion). Since, we want the next partition to start the following day, we take this date as the upper boundary. Although, there should not exist any record in our table with a date in the future, we adjust the upper bound just in case (probably it would be better to return an error in that case, but for clarity, we omit error handling here).

<code>DECLARE @start_dt datetime2, @end_dt datetime2;
SELECT @start_dt = MIN(create_date) FROM dbo.AuditTab;
SET @start_dt = DATEADD(dd, DATEDIFF(dd, 0, @start_dt), 0);
SELECT @end_dt = MAX(create_date) FROM dbo.AuditTab;
SET @end_dt = CASE WHEN @end_dt &lt; GETDATE() THEN GETDATE() ELSE @end_dt END;
SET @end_dt = DATEADD(dd, DATEDIFF(dd, 0, @end_dt) + 1, 0);</code>

<code>CREATE PARTITION FUNCTION PF_Date (datetime2) AS RANGE RIGHT FOR VALUES (@start_dt, @end_dt);
CREATE PARTITION SCHEME PS_Date AS PARTITION PF_Date TO ([PRIMARY], [PRIMARY], [PRIMARY]);</code>

Our AuditTab table has been created in the PRIMARY filegroup. It’s important that the middle partition is mapped to the same filegroup where the original table was created in.

Next, we create a check constraint on our table enforcing that all current rows (plus those being added until we start partitioning the table) are within the boundaries of the middle partition. This is the most expensive operation in the whole process. Although, it will take only a few seconds on a table of this size, the schema modification lock, which is being acquired while creating this check constraint, blocks all DML operations on the table. Therefore, we perform this operation right ahead (preferably at a period of lower insert activity).

<code>DECLARE @check nvarchar(max), @sql nvarchar(max);</code>

<code>SET @check = N' CHECK (create_date &gt;= ''' + CONVERT(nvarchar, @start_dt, 112) +
N''' AND create_date &lt; ''' + CONVERT(nvarchar, @end_dt, 112) + N''')';</code>

<code>SET @sql = N'ALTER TABLE dbo.AuditTab ADD CONSTRAINT chk_date' + @check;
EXEC sp_executesql @sql;</code>

Now, we create a temporary table that has an identical structure as our original table, is in the same filegroup, has the same indexes, and the same constraints. This is necessary, because later we want to switch the data from our original table into this temp table. Thereby, we can partition the empty original table, and later switch the data back from the temp table. This has the advantage that we do not alter the underlying database object, i.e. object ownership, all permission settings, and other constructs that reference the table, like triggers or extended properties, etc. remain unaffected.

<code>CREATE TABLE dbo.AuditTab_Temp (…,create_date datetime2 NOT NULL, …) ON [PRIMARY];
CREATE CLUSTERED INDEX ix ON dbo.AuditTab_Temp (create_date);</code>

<code>SET @sql = N'ALTER TABLE dbo.AuditTab_Temp ADD' + @check;
EXEC sp_executesql @sql;</code>

Now, we perform the actual transformation of the original table into a partitioned table. All operations are grouped within a transaction, so if anything fails, the transaction would be rolled back. First, we switch the original table into the temporary table we just created. Then, we partition the, now empty, original table by rebuilding the clustered index. Finally, we switch the temp table back into the middle partition of the now partitioned original table. Since we did create the check constraint that is necessary for this switch already on the original table and then on the temporary table, it is not necessary to perform this expensive check constraint creation on the temporary table within the transaction after switching the data from the original table into the temporary table.

<code>BEGIN TRAN;
ALTER TABLE dbo.AuditTab SWITCH TO dbo.AuditTab_Temp;
CREATE CLUSTERED INDEX ix_AuditTab ON dbo.AuditTab (create_date) WITH (DROP_EXISTING = ON) ON PS_Date (create_date);
ALTER TABLE dbo.AuditTab_Temp SWITCH TO dbo.AuditTab PARTITION 2;
COMMIT TRAN;</code>

Note, this transaction only consists of meta-data changes and therefore performs very fast. In principal, nothing has the potential to fail within this transaction since we enforce that all data fit into the target partition by means of the check constraint. Anyway, it’s recommended to put this transaction within a try-block, and rollback the transaction in the catch-block.

Finally, we drop the additional objects being created, i.e. the temp table and the check constraint.

<code>DROP TABLE dbo.AuditTab_Temp;
ALTER TABLE dbo.AuditTab DROP CONSTRAINT chk_date;
ALTER TABLE dbo.AuditTab SET (LOCK_ESCALATION = AUTO); </code>

We also set the LOCK_ESCALATION setting for our original table to AUTO, which causes lock escalations on the partition level, instead of the table level. Thereby, if saving space is a must, we may continue deleting the data that is older than 30 days from the big partition on a daily basis, but now without having to lock the whole table. Hence, the deletes do not affect the partitions where the new inserts are occurring and hence, increasing the concurrency.
<h3><strong>Defining the partition management job</strong></h3>
Now that the table is being partitioned, the only thing left is to define the daily partition management activities. We create a SQLAgent job for this, which runs every day before midnight, starting at the day where we partitioned the table. This job consists of one TSQL step executing the following batch:

<code>DECLARE @fid int, @num_part int, @first_val sql_variant;</code>

<code>SELECT @fid = function_id, @num_part = fanout
FROM   sys.partition_functions WHERE name = 'PF_Date';</code>

<code>IF @num_part &gt;= 32
BEGIN
CREATE TABLE dbo.AuditTab_Archive (…, create_date datetime2 not null, …);
CREATE CLUSTERED INDEX ix ON dbo.AuditTab_Archive (create_date);
ALTER TABLE dbo.AuditTab SWITCH PARTITION 2 TO dbo.AuditTab_Archive;
DROP TABLE dbo.AuditTab_Archive;</code>

<code>SELECT @first_val = value FROM sys.partition_range_values
WHERE  function_id = @fid AND boundary_id = 1 AND parameter_id = 1;</code>

<code>ALTER PARTITION FUNCTION PF_Date() MERGE RANGE (@first_val);
END</code>

<code>ALTER PARTITION SCHEME PS_Date NEXT USED [PRIMARY];
ALTER PARTITION FUNCTION PF_Date() SPLIT RANGE (DATEADD(dd, DATEDIFF(dd, 0, GETDATE()) + 2, 0));</code>

As long as we haven’t reached the final target of 32 partitions (note there is one empty partition at the beginning and one at the end), we just add a new partition, mapped to the PRIMARY filegroup, by splitting the last partition on the date that follows the next day. Hence, starting at midnight all new records will go into the partition preceding the new one (the last partition is always left empty so that the SPLIT operation is always performed on an empty partition). Once we have reached 30 partitions with data, we drop the partition with the oldest data, which always happens to be partition 2, by switching the data out into an archive table (which later is being dropped), and merging the (empty) partitions 1 and 2 using the lowest boundary value in our partition range.
<h3><strong>Conclusion</strong></h3>
In case you intend to partition a table where it is acceptable not to partition the existing data, but only all future data, using the strategy outlined above it is possible to partition even huge tables within seconds without major disruption for parallel workload.

By the way, this strategy also has been implemented in the new version of PTF (see <a href="https://ptf.codeplex.com/">https://ptf.codeplex.com/</a>) by setting the parameter <strong>@fast_mode = 1</strong> in procedure <strong>PartitionTable</strong>. Hence, in PTF executing the following command would perform the identical steps:

<code>EXEC ptf.PartitionTable 'dbo.AuditTab', 'PS_Date', 'create_date', @fast_mode = 1</code>]]></content:encoded>
    </item>
    <item>
      <title>Partitioning of Temporal Tables in SQL Server 2016</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/partitioning-of-temporal-tables-in-sql-server-2016</link>
      <pubDate>Wed, 20 Jan 2016 05:51:09 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/2016/01/20/partitioning-of-temporal-tables-in-sql-server-2016/</guid>
      <description><![CDATA[&#160;  Microsoft SQL Server 2016 introduces system-versioned temporal tables, which allow for...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 16pt; mso-ansi-language: en-us"></span></b></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p> <span lang="EN-US" style="mso-ansi-language: en-us">Microsoft SQL Server 2016 introduces system-versioned temporal tables, which allow for automatically keeping a history of data changes in a separate history table and to retrieve the status of your data at any time in the past. Here I don’t want to go into all the gory details of their implementation. See the relevant BOL pages <a href="https://msdn.microsoft.com/en-US/library/dn935015.aspx"><font color="#0563c1">https://msdn.microsoft.com/en-US/library/dn935015.aspx</font></a> or <a href="https://blogs.technet.com/b/dataplatforminsider/archive/2016/01/11/effortlessly-analyze-data-history-using-temporal-tables.aspx"><font color="#0563c1">https://blogs.technet.com/b/dataplatforminsider/archive/2016/01/11/effortlessly-analyze-data-history-using-temporal-tables.aspx</font></a> for an exhaustive description of temporal tables. </span>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">In this Blog I just want to show how table partitioning affects temporal tables. Like any other table, temporal tables can be partitioned (at least, if you are running on Enterprise Edition of SQL Server). In order to partition a temporal table while creating the table, simply add the ON (&lt;partition scheme&gt;) clause to the CREATE TABLE statement, e.g. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">CREATE TABLE MyTemporalTable ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int PRIMARY KEY, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 GENERATED ALWAYS AS ROW START, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 GENERATED ALWAYS AS ROW END,</span><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"> </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">) ON MyPartScheme (Id) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">WITH (SYSTEM_VERSIONING = ON) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">But note, when doing so, the partitioning column has to be part of the primary key that has to be specified with each temporal table. If you do not explicitly specify a name for the history table, one will be generated automatically for you with the name MSSQL_TemporalHistoryFor_<i style="mso-bidi-font-style: normal">nnnn</i>, where <i style="mso-bidi-font-style: normal">nnnn</i> is the object ID of the temporal table. And, this history table is going to be partitioned the same way as the underlying temporal table, i.e. using the same partitioning column and the same partition scheme and function. But, having more than one table partitioned using the same partition function is not a good practice, since every Merge or Split operation on the partition function affects both tables at the same time and may cause undesired data movements if you do not pay attention to it. Therefore, I strongly advise not to partition a temporal table while creating it together with the associated history table. And, by the way, I do not see any good reason for partitioning the temporal table and its history table on the very same column and using the same partition scheme and function, since both tables serve different purposes. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="mso-ansi-language: en-us">Partitioning the Temporal Table </span></b></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">So let us view the aspects of partitioning for each of the tables separately. For the temporal table you typically might consider partitioning if you want to balance data storage on different filegroups and their associated physical data files, or if you want to utilize partitions for fast data loading. Note, that adding new rows to a temporal table has no effect on the history table. Therefore, switching data into a partition of a temporal table is a valid operation. For a table to be switched in the PERIOD FOR SYSTEM_TIME columns must be defined identically, except for the HIDDEN attribute, and the indexes must match. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">If the temporal table is being created like: </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">CREATE TABLE MyTemporalTable ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int CONSTRAINT PK_MyTemporalTable PRIMARY KEY, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 GENERATED ALWAYS AS ROW START, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 GENERATED ALWAYS AS ROW END,</span><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"> </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">WITH (SYSTEM_VERSIONING = ON) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">You may partition this table by recreating the primary key: </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">CREATE UNIQUE CLUSTERED INDEX PK_MyTemporalTable ON MyTemporalTable (Id) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">WITH (DROP_EXISTING = ON) ON MyPartScheme (Id) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Next, create the staging table to be switched in and fill it with data (declaring the system_time columns as HIDDEN might be beneficial here): </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">CREATE TABLE MyTemporalStaging ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int PRIMARY KEY, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 GENERATED ALWAYS AS ROW START HIDDEN, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 GENERATED ALWAYS AS ROW END HIDDEN,</span><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"> </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;"><span style="mso-spacerun: yes">&#160; </span>PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">And finally, after splitting the last partition, switch the staging table into the new last partition of the temporal table: </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #262626; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 217; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=85000 lumo=15000&quot;">ALTER TABLE MyTemporalStaging SWITCH TO MyTemporalTable PARTTION @last_partition </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">On the other hand, switching partitions out from the temporal table effectively means deleting rows and therefore must be reflected in the history table as well. Because this cannot be handled by the system, switching partitions out of a temporal table is not a supported operation and returns error 13546 when doing so. If you really need to switch out partitions from a temporal table, you first have to disable system versioning on the temporal table, and turn it on again after the switch. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="mso-ansi-language: en-us">Partitioning of the History Table for Managing Data Retention </span></b></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">A temporal history table steadily grows as you perform data modifications on your temporal table. Hence, the history table might become really big, and at some point you may face the need to remove old and no longer needed row versions from your history table in order to reclaim space. As of CTP 3 automatic data retention isn’t yet implemented for temporal history tables. So you have to do it on your own. See also <a href="https://msdn.microsoft.com/en-us/library/mt637341.aspx"><font color="#0563c1">https://msdn.microsoft.com/en-us/library/mt637341.aspx</font></a>. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">But, simply deleting rows from the history table isn’t allowed. You have to disable system versioning prior to this, and you better perform these steps within a transaction in order to block any data modification on the temporal table while system versioning is being disabled. So, this would look like: </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">BEGIN TRANSACTION </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">ALTER TABLE &lt;temporal table&gt; SET (SYSTEM_VERSIONING = OFF) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">DELETE FROM &lt;history table&gt; WHERE &lt;period end column&gt; &lt;= @cut_off_date </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">ALTER TABLE &lt;temporal table&gt; SET (SYSTEM_VERSIONING = ON </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>(HISTORY_TABLE = &lt;history table&gt;, DATA_CONSISTENCY_CHECK = OFF)) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">COMMIT TRANSACTION </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Depending on the amount of rows being deleted, this might cause lock escalation and result in an exclusive table lock on the history table, which is further propagated to the temporal table, and thus, also blocks all read operations on the temporal table for the duration of this transaction. Moreover, this operation may result in a huge amount of rows being generated in the transaction log. Thus, for a big history table this is not the recommended procedure for data cleansing. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Since switching partitions out of the history table is a supported operation, partitioning of the history table is the preferred method to implement such a data retention scheme on a temporal history table. Simply create a partition function that covers your envisioned retention period and deletion frequency and partition the history table on the end column of the system time period. Note, that the clustered index that is created automatically on the history table has the two system time period columns as key columns and therefore, is perfectly suited for partitioning on this column. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">If your temporal table has been defined as </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">CREATE TABLE dbo.TemporalTable ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int PRIMARY KEY, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 GENERATED ALWAYS AS ROW START, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 GENERATED ALWAYS AS ROW END, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.TemporalHistory)) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">the history table, if it does not yet exist, will be created equivalent to </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">CREATE TABLE dbo.TemporalHistory ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int NOT NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 NOT NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 NOT NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>INDEX ix_TemporalHistory CLUSTERED (ValidTo, ValidFrom) WITH (DATA_COMPRESSION = PAGE) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Therefore, if you’re going to partition the history table on column ‘ValidTo’ using the previously created partition scheme ‘MyPartScheme’, you can accomplish this by recreating the clustered index: </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">CREATE CLUSTERED INDEX ix_TemporalHistory ON dbo.TemporalHistory (ValidTo, ValidFrom) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">WITH (DATA_COMPRESSION = PAGE, ONLINE = ON, DROP_EXISTING = ON) ON MyPartScheme (ValidTo) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">If you have created your own indexes on the history table to replace or supplement the default clustered index, the procedure to partition the history table might look slightly different. Especially, if you have defined a columnstore index, that index has to be dropped prior to partitioning the history table, and recreated afterwards. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Now, whenever you are going to delete the data in the partition with the oldest ‘ValidTo’ values, you have to create an archive table that matches the structure and the clustered index of the history table, switch the partition out to this archive table, merge the two left most partitions, and finally drop the archive table. Let’s say ‘MyPartFunction’ is the name of the partition function our partition scheme ‘MyPartScheme’ is based on, then the following batch would accomplish this maintenance job (with RANGE RIGHT partitions, the leftmost partition should be left empty): </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">DECLARE @v datetime2, @p int; </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">SELECT @v = CONVERT(datetime2, prv.value), @p = 1 + pf.boundary_value_on_right </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">FROM sys.partition_functions pf JOIN sys.partition_range_values prv </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">ON prv.function_id = pf.function_id AND prv.parameter_id = 1 AND prv.boundary_id = 1 </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">WHERE pf.name = 'MyPartFunction'; </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">CREATE TABLE dbo.TemporalHistoryArchive ( </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Id int NOT NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>Data nvarchar(1000) NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidFrom datetime2 NOT NULL, </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>ValidTo datetime2 NOT NULL </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"><span style="mso-spacerun: yes">&#160; </span>INDEX ix_TemporalHistoryArchive CLUSTERED (ValidTo, ValidFrom) WITH (DATA_COMPRESSION = PAGE) </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">); </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">ALTER TABLE dbo.TemporalHistory SWITCH PARTITION @p TO dbo.TemporalHistoryArchive; </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">ALTER PARTITION FUNCTION MyPartFunction() MERGE RANGE (@v); </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;">DROP TABLE dbo.TemporalHistoryArchive;</span><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: red; mso-ansi-language: en-us; mso-bidi-font-family: consolas"> </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; color: #0d0d0d; mso-ansi-language: en-us; mso-themecolor: text1; mso-themetint: 242; mso-style-textfill-fill-color: #0d0d0d; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-colortransforms: &quot;lumm=95000 lumo=5000&quot;"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-autospace: ; mso-layout-grid-align: none"><span lang="EN-US" style="font-size: 9.5pt; font-family: consolas; mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Although SQL Server 2016 added the WITH PARTTITIONS clause to the TRUNCATE TABLE statement to allow for operations like that, using the statement “TRUNCATE TABLE TemporalHistory WITH (PARTITIONS (@p))” returns error 13545. Hence, even if you do not intend to keep the archived data, you have to follow the more cumbersome process of creating an archive table, and dropping it again after having switched out the partition to it. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Note, that the next version of PTF on <a href="https://ptf.codeplex.com/"><font color="#0563c1">https://ptf.codeplex.com</font></a> will support SQL Server 2016 and temporal tables. Thereby, the above maintenance script could be substituted with the single statement:       <br />EXEC ptf.DropPartitions 'dboTemporalHistory' </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="mso-ansi-language: en-us">Summary </span></b></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">With temporal tables, both the temporal table itself, as well as its associated history table can be partitioned. On the partitioned temporal table, the only supported operation is the switch in, while on the partitioned history table we only may switch out partitions without disabling system versioning. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span>    <p>&#160;</p> </p>    <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us">Especially, partitioning the history table is recommended if you want to implement some means of data cleansing in response to excessive data growth in this table. </span></p>  <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="mso-ansi-language: en-us"></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Partitioned Table Framework (PTF) Project has been published on CodePlex</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/partitioned-table-framework-ptf-project-has-been-published-on-codeplex</link>
      <pubDate>Fri, 09 Nov 2012 07:35:23 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/2012/11/09/partitioned-table-framework-ptf-project-has-been-published-on-codeplex/</guid>
      <description><![CDATA[Today I did publish the PTF project on CodePlex (see https://ptf.codeplex.com/) which&nbsp;consists...]]></description>
      <content:encoded><![CDATA[<p>Today I did publish the PTF project on CodePlex (see <a href="https://ptf.codeplex.com/">https://ptf.codeplex.com/</a>) which&nbsp;consists of&nbsp;a set of T-SQL stored procedures for managing partitioned tables in SQL Server. These procedures&nbsp;may be used in your SQL Agent Jobs or SSIS SQL Tasks that load data into staging tables of your data warehouse and then switch these tables into partitions of your partitioned fact tables, i.e. implementing a sliding window scenario. All SQL Server versions and Editions that allow for partitioned tables are being supported.</p>
<p>The following activities can be accomplished:</p>
<ul>
<li>Creating a staging table.</li>
<li>Preparing a staging table, i.e. creating Indexes and constraints.</li>
<li>Performing partition switches and Partition merges and splits.</li>
<li>Unloading or uploading of specific partitions.</li>
<li>Converting an unpartitioned table into a partitioned one.</li>
</ul>
<p>For detailed documentation download the PTF.docx file from the codeplex project.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Hardening an ASP.NET session state database</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/hardening-an-asp-net-session-state-database</link>
      <pubDate>Mon, 10 Jan 2011 02:28:29 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/2011/01/10/hardening-an-asp-net-session-state-database/</guid>
      <description><![CDATA[Recently I did come across a problem with the ASPState database of ASP.NET. This database is used to...]]></description>
      <content:encoded><![CDATA[<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">Recently I did come across a problem with the ASPState database of ASP.NET. This database is used to store the ASP.NET user session data in a SQL Server instance. The database is being installed by executing Aspnet_regsql.exe with parameter &ndash;ssadd (see </span><a href="https://msdn.microsoft.com/library/ms178586.aspx"><span style="font-size: small; font-family: Calibri;">Session-State Modes</span></a><span style="font-size: small;"><span style="font-family: Calibri;">). Principally there are two configuration modes: persistent and non-persistent, the latter being the default.<span style="mso-spacerun: yes;">&nbsp; </span>In persistent mode the two tables ASPStateTempSessions and ASPStateTempApplications, which hold the current ASP state, are being created in the ASPState database, whereas in the non-persistent mode both tables are being created in tempdb and are recreated each time SQL Server restarts using the startup procedure CreateTempTables. Thus, in persistent mode the ASP state can survive a SQL Server restart, while in non-persistent mode the state is lost whenever SQL Server restarts, which usually is not a problem.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">This setup works perfectly for members of the sysadmin fixed server role or the owner of the ASPState database. But, since no permissions are being granted by the setup program, all other principals do not have access to the ASP.NET procedures. When ASP.NET is configured to store its state in SQL Server, the user that connects to the ASPState database is hardcoded together with the password in the connection string stored within the &lt;sessionState&gt; element of the Web.config file. Although there are ways to encrypt this information (see </span><a href="https://msdn.microsoft.com/library/53tyfkaw.aspx"><span style="font-size: small; font-family: Calibri;">Encrypting Configuration Information Using Protected Configuration</span></a><span style="font-size: small;"><span style="font-family: Calibri;">), this still could a pose the risk for a<span style="mso-spacerun: yes;"> </span>security breach when using an administrative account for this purpose. Thus, in order to harden your ASP.NET environment it would be more desirable to have a low privileged SQL Server login and granting this login access to the ASPState database. Now, the only thing that is left is to grant this database user (or the public role) EXECUTE rights on the ASPState procedures. That is all that needs to be done for the persistent mode. But, for the non-persistent mode things are a little bit more tricky.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">In the persistent case, it is sufficient to grant EXECUTE rights on the procedures, because access to the tables works by means of an ownership chain, i.e. if the owner of a procedure also owns the tables being accessed by the procedures, no additional checks are being performed when accessing those tables. In the ASPState database the owner of all objects is also the database owner, i.e. the account who did create the ASPState database when running the Aspnet_regsql tool. In the non-persistent mode, where the tables do not reside in the ASPState database but are located in tempdb, there is no direct ownership chain and therefore one more step has to be performed:<span style="mso-spacerun: yes;">&nbsp; </span>a cross-database ownership chain has to be established.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">First, we need to allow cross-database ownership chains for the participating databases. This can be set server wide by means of a configuration parameter. But this could create undesired security holes. Therefore, it&rsquo;s always recommended to enable this on the database level. On tempdb this already has been set by default. But on ASPState we have to perform this manually, executing the &ldquo;</span></span><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">ALTER</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> <span style="color: blue;">DATABASE</span> ASPState <span style="color: blue;">SET</span> <span style="color: blue;">DB_CHAINING</span> <span style="color: blue;">ON</span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">&rdquo; statement. But still this does not suffice. We are still receiving the error &ldquo;</span></span><span style="font-size: 10pt; color: black; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-themecolor: text1; mso-no-proof: yes;" lang="EN-US">The INSERT permission was denied on the object 'ASPStateTempSessions', database 'tempdb', schema 'dbo'</span><span style="font-size: 10pt; color: gray; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">.</span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">&rdquo; when calling an ASPState procedure, like TempInsertStateItemShort. The problem we are still facing is the fact that cross-database ownership chaining does not work on a user basis, but on a login basis. The owner of the ASPState database is the login that did create the database. But for tempdb it is always the <b style="mso-bidi-font-weight: normal;">sa</b> login. Thus, for the cross-database ownership chain to work the owners of both databases have to match the same principal. Since it is not practical to change the ownership of tempdb, we have to change it on database ASPState. This is being accomplished by executing &ldquo;</span></span><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">ALTER</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> <span style="color: blue;">AUTHORIZATION</span> <span style="color: blue;">ON</span> <span style="color: blue;">DATABASE</span><span style="color: gray;">::</span>ASPState <span style="color: blue;">TO</span> sa</span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">&rdquo;.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">To summarize, here are the steps to be performed in order to harden your ASP.NET applications that are using SQL Server mode for storing the session state:<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">Either create a low privileged login for the identity your ASP.NET applications run with (see </span><a href="https://msdn.microsoft.com/library/dwc1xthy.aspx"><span style="font-size: small; font-family: Calibri;">Configuring ASP.NET Process Identity</span></a><span style="font-size: small;"><span style="font-family: Calibri;">) and Integrated Security is used in the sqlConnectionString attribute, or create a SQL Server login to be used for this purpose. After having created the ASPState database by running Aspnet_regsql.exe, define this login as a user on the ASPState database. Then run the following script:<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">USE</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> <span style="color: blue;">master<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">GO<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">IF</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> <span style="color: gray;">EXISTS</span> <span style="color: gray;">(<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp; </span><span style="color: blue;">SELECT</span> <span style="color: gray;">*</span> <span style="color: blue;">FROM</span> tempdb<span style="color: gray;">.</span><span style="color: green;">sys.tables</span><o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;</span><span style="mso-spacerun: yes;">&nbsp; </span><span style="color: blue;">WHERE</span><span style="mso-spacerun: yes;">&nbsp; </span><span style="color: fuchsia;">schema_id</span> <span style="color: gray;">=</span> 1 <span style="color: gray;">AND</span> <span style="color: blue;">name</span> <span style="color: gray;">=</span> <span style="color: red;">'ASPStateTempSessions'</span><span style="color: gray;">)<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">BEGIN<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp; </span><span style="color: blue;">ALTER</span> <span style="color: blue;">DATABASE</span> ASPState <span style="color: blue;">SET</span> <span style="color: blue;">DB_CHAINING</span> <span style="color: blue;">ON</span><span style="color: gray;">;<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp; </span><span style="color: blue;">ALTER</span> <span style="color: blue;">AUTHORIZATION</span> <span style="color: blue;">ON</span> <span style="color: blue;">DATABASE</span><span style="color: gray;">::</span>ASPState <span style="color: blue;">TO</span> sa<span style="color: gray;">;<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">END<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">GO<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">USE</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> ASPState<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">GO<o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">DECLARE</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> @cmd <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span><span style="color: fuchsia;">max</span><span style="color: gray;">)<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">SET</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> @cmd <span style="color: gray;">=</span> N<span style="color: red;">''<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: red; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">SELECT</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> @cmd <span style="color: gray;">=</span> @cmd <span style="color: gray;">+</span><o:p></o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes;">&nbsp;</span>N<span style="color: red;">'GRANT EXECUTE ON dbo.'</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">QUOTENAME</span><span style="color: gray;">(</span><span style="color: blue;">name</span><span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">' TO PUBLIC;'<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">FROM</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp;&nbsp; </span><span style="color: green;">sys.objects<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">WHERE</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="mso-spacerun: yes;">&nbsp; </span><span style="color: blue;">type</span> <span style="color: gray;">=</span> <span style="color: red;">'P'</span> <span style="color: gray;">AND</span> <span style="color: fuchsia;">schema_id</span> <span style="color: gray;">=</span> 1 <span style="color: gray;">AND</span> <span style="color: blue;">name</span> <span style="color: gray;">LIKE</span> <span style="color: red;">'Temp%'<o:p></o:p></span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: red; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US">EXEC</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"> <span style="color: gray;">(</span>@cmd<span style="color: gray;">)</span></span></p>
<p style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;" class="MsoNormal"><span style="font-size: 10pt; font-family: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes;" lang="EN-US"><span style="color: gray;"><o:p></o:p></span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>New Limit for Number of Partitions in SQL Server 2008 SP2</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/new-limit-for-number-of-partitions-in-sql-server-2008-sp2</link>
      <pubDate>Mon, 29 Nov 2010 06:34:09 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/2010/11/29/new-limit-for-number-of-partitions-in-sql-server-2008-sp2/</guid>
      <description><![CDATA[Good news for all that suffered from the 1.000 partition limit inherent with the current table...]]></description>
      <content:encoded><![CDATA[<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small; font-family: Calibri;">Good news for all that suffered from the 1.000 partition limit inherent with the current table partitioning implementation in Microsoft SQL Server 2005 and 2008. With the release of SP2 for SQL Server 2008 the bar has been raised to a new threshold of 15.000 partitions, which should be enough for daily data loads and makes even smaller load cycles a reality. See the whitepaper </span><a href="https://download.microsoft.com/download/B/E/1/BE1AABB3-6ED8-4C3C-AF91-448AB733B1Af/Support_for_15000_Partitions.docx"><span style="font-size: small; font-family: Calibri;">Support for 15,000 Partitions in SQL Server 2008 SP2</span></a><span style="font-size: small;"><span style="font-family: Calibri;"> for details.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">But this feature does not come out of the box. It has to be enabled on a database by database basis after having upgraded your SQL Server 2008 instances to SP2 (users of SQL Server 2008 R2 still have to wait for SP1 to benefit from this change). You do this by calling the new system stored procedure <b style="mso-bidi-font-weight: normal;">sp_db_increased_partitions</b>. For instance, to enable the database MyDataWarehouse for increased partitions, simply call:<br />EXEC sp_db_increased_partitions @dbname = &lsquo;MyDataWarehouse&rsquo;, @increased_partitions = &lsquo;on&rsquo;<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">Note, that this operation increases the version of the database from 655 to 662. This has implications for the ability to upgrade this database or to attach a detached copy of the altered database to another server. The target system must have the same or a higher database version. Thus, you cannot upgrade this server to SQL Server 2008 R2 RTM (which has version 661), or attach the database to a SQL Server 2008 SP1 instance. And there are also implications for log shipping or mirroring where the partner servers also have to be on SP2 level. While with log shipping it is sufficient to run the procedure just on the primary server (the corresponding log entry is propagated to the secondary servers and also applied there), with mirroring the mirror has to be broken, and the procedure being executed on both principal and mirror server before the mirror can be re-established.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">And there are a few more caveats to consider:<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt 36pt; text-indent: -18pt; mso-list: l0 level1 lfo1;" class="MsoListParagraph"><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">it can only be applied to user databases.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt 36pt; text-indent: -18pt; mso-list: l0 level1 lfo1;" class="MsoListParagraph"><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">you cannot execute this proc within an open transaction.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt 36pt; text-indent: -18pt; mso-list: l0 level1 lfo1;" class="MsoListParagraph"><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">you must be the only user in the database since this proc tries to aquire an exclusive lock on the DB.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt 36pt; text-indent: -18pt; mso-list: l0 level1 lfo1;" class="MsoListParagraph"><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">this database must not participate in replication, CDC or change tracking.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt 36pt; text-indent: -18pt; mso-list: l0 level1 lfo1;" class="MsoListParagraph"><span style="font-family: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">it is not supported for this upgraded database to have a nonaligned index defined on any partitioned table.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;">Also, the partitioning Wizards in SQL Server Management Studio 2008 have not been updated to cater for the increased partition limit. Therefore, you have to use T-SQL to manage those partitions.<o:p></o:p></span></span></span></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><span style="mso-ansi-language: EN-US;" lang="EN-US"><o:p><span style="font-size: small; font-family: Calibri;">&nbsp;</span></o:p></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Inside of Table and Index Partitioning in Microsoft SQL Server</title>
      <link>https://docs.microsoft.com/archive/blogs/hanspo/inside-of-table-and-index-partitioning-in-microsoft-sql-server</link>
      <pubDate>Fri, 21 Aug 2009 03:23:00 GMT</pubDate>
      <dc:creator><![CDATA[HansPo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/hanspo/2009/08/21/inside-of-table-and-index-partitioning-in-microsoft-sql-server/</guid>
      <description><![CDATA[&nbsp;
&nbsp;
Introduction
&nbsp;
With those huge fact tables,&nbsp;you typically find in...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Introduction<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">With those huge fact tables<SPAN class=GramE>,<SPAN style="mso-spacerun: yes">&nbsp;</SPAN>you</SPAN> typically find in today’s data warehouses, you’re often confronted with restrictions concerning the manageability of these tables and their indexes. Some actions like generating full database backups, checking the database consistency, or reorganizing indexes are becoming prohibitive in terms of time required to perform these activities. Additionally, bulk loading big chunks of data into these tables incurs big overhead for index maintenance and transaction logging and results in reduced concurrency on the tables due to blocking.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Most of these problems are being addressed by a feature available in the Enterprise Edition of SQL Server 2005 and later, called table and index partitioning. Quite a few information about partitioning is available in various sources, like SQL Server Books Online, or the excellent White Papers “Partitioned Tables and Indexes in SQL Server 2005" <A href="https://msdn.microsoft.com/library/ms345146.aspx">https://msdn.microsoft.com/library/ms345146.aspx</A>,<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>or “Partitioned Table and Index Strategies Using SQL Server 2008" <A class="" href="https://msdn.microsoft.com/library/dd578580.aspx" mce_href="https://msdn.microsoft.com/library/dd578580.aspx">https://msdn.microsoft.com/library/dd578580.aspx</A>.&nbsp;In&nbsp;the following, I’d like to dig a little bit deeper into this topic, showing the effects of partitioning on SQL Server metadata, with special focus on sliding window scenarios. Also, I’ll present some T-SQL queries that might come handy for administering your partitions. And finally, I will talk about the improvements SQL Server 2008 has up its sleeves for partitioning.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Table Partitioning <o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Partitioning a table means splitting the table data horizontally into smaller units, called <SPAN class=GramE>partitions, that</SPAN> are easier to manage than the table as a whole. While a non-partitioned table is stored on a single filegroup, each of the partitions of a partitioned table can be mapped to a different filegroup, thus allowing for better control over the physical distribution of table space. With this separation, filegroup backups and checking the consistency of a single filegroup instead of the whole database are becoming a reality. Additionally, by marking some filegroups, that are associated with partitions that do not change, as READ_ONLY, you can take advantage of the new partial backup feature or the reduced locking when querying data on those filegroups.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">So how does SQL Server determine, which partition a row of a partitioned table belongs to? For this, we first have to identify the column by which the table is being partitioned. The data type of this column defines the maximum range of possible values, e.g. for integer the range is from negative infinity to positive infinity. Next, this range is further divided into consecutive, non-overlapping sub-ranges, each of them defining a partition range.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Thus, the sub-range, into which the value of the partitioning column for a particular row falls, determines the partition the row belongs to.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Therefore, the first decision to make, when creating a partitioned table, is which column to use to partition the table. This column is called the partitioning column. In SQL Server 2005 and SQL Server 2008 only one column can be used for partitioning a table, but this may change in future releases. The decision which column to choose will be based on data distribution and the intended usage of the partitioned table and is mostly based on the same criteria we apply, when identifying the columns of a clustered index. In fact, the partitioning column also has to be a member of the clustered index keys.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It’s obvious, that a partitioning column needs to be a fairly static one, as a change of the partitioning column also might result in a change of the partition the row belongs to and thus, the row would have to be copied physically from one partition to another. If the partitioned table is intended for business analysis purpose, the most predominant dimension used for analysis is a good candidate for the partitioning column, e.g. date, product group, sales region.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>If the table stores historical data and at any time we only want to keep a certain range of data, i.e. we constantly age old data out and move new data in, the table needs to be partitioned on some date value stored in the table. This is the typical usage of the sliding window scenario as we will discover later.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Partition Functions<o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Once the partitioning column has been identified, we need to define the number of partitions to use and the boundary values for each of the partition ranges. This designation has to be set up by means of a <B style="mso-bidi-font-weight: normal">Partition Function</B>. The partition function is being created using the following T-SQL statement:<o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">CREATE PARTITION FUNCTION </SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US">&lt;<I style="mso-bidi-font-style: normal">name</I>&gt;<B style="mso-bidi-font-weight: normal"> (</B>&lt;<I style="mso-bidi-font-style: normal">type</I>&gt;<B style="mso-bidi-font-weight: normal">)</B> <B style="mso-bidi-font-weight: normal">AS RANGE</B> {<B style="mso-bidi-font-weight: normal">LEFT</B> | <B style="mso-bidi-font-weight: normal">RIGHT</B>} <B style="mso-bidi-font-weight: normal">FOR VALUES (</B><I style="mso-bidi-font-style: normal">v<SUB>1</SUB></I><SPAN class=GramE>, …,</SPAN> <SPAN class=SpellE><I style="mso-bidi-font-style: normal">v<SUB>n</SUB></I></SPAN><B style="mso-bidi-font-weight: normal">);</B> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">By specifying n boundary values v<SUB>1</SUB> through <SPAN class=SpellE>v<SUB>n</SUB></SPAN> of the given type, this function defines <SPAN class=GramE>n+1 partitions</SPAN>. A maximum of 1000 partitions can be created this way. The type the function is based on must be of an integral SQL type<SPAN class=GramE>,<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>LOB’s</SPAN>, xml, timestamp and user defined types are excluded. The order of the boundary values does not matter as long as all values are distinct. The system orders them implicitly in case they are not given in ascending order. LEFT or RIGHT specifies to which side of a boundary value the pertaining partition extends. If the boundary values are arranged in ascending order on a horizontal axis, the partition range alignment can be illustrated as:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN class=SpellE><SPAN class=GramE>partition<SUB>i</SUB></SPAN></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>partition<SUB>i+1</SUB> <BR></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US">LEFT:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>---<SPAN class=GramE>|<B style="mso-bidi-font-weight: normal">[</B></SPAN>---------|<B style="mso-bidi-font-weight: normal">]</B>---<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>RIGHT:<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>---<B style="mso-bidi-font-weight: normal">[</B>|---------<B style="mso-bidi-font-weight: normal">]</B>|---<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN class=GramE>v<SUB>i-1</SUB></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>v<SUB>i</SUB><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN class=SpellE>v<SUB>i</SUB></SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>v<SUB>i+1</SUB> </SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">This arrangement probably becomes more obvious when listing for the partitioning column <B style="mso-bidi-font-weight: normal">x</B> the partitions and their pertaining ranges in tabular format:</SPAN>&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<DIV class=Section1>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-yfti-tbllook: 1184; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt" cellSpacing=0 cellPadding=0 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">RANGE LEFT<o:p></o:p></SPAN></B></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">RANGE RIGHT<o:p></o:p></SPAN></B></P></TD></TR>
<TR style="mso-yfti-irow: 1">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">partition<SUB>1</SUB>:<o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &lt;= v<SUB>1</SUB><o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &lt; v<SUB>1</SUB> <o:p></o:p></SPAN></P></TD></TR>
<TR style="mso-yfti-irow: 2">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">partition<SUB>2</SUB>:<o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt; v<SUB>1</SUB> AND x &lt;= v<SUB>2</SUB><o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt;= v<SUB>1</SUB> AND x &lt; v<SUB>2</SUB><o:p></o:p></SPAN></P></TD></TR>
<TR style="mso-yfti-irow: 3">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>:<o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P></TD></TR>
<TR style="mso-yfti-irow: 4">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN class=SpellE><SPAN lang=EN-US style="mso-ansi-language: EN-US">partition<SUB>n</SUB></SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">:<o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt; v<SUB>n-1</SUB> AND x &lt;= <SPAN class=SpellE>v<SUB>n</SUB></SPAN><o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt;= v<SUB>n-1</SUB> AND x &lt; <SPAN class=SpellE>v<SUB>n</SUB></SPAN><o:p></o:p></SPAN></P></TD></TR>
<TR style="mso-yfti-irow: 5; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 153.5pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">partition<SUB>n+1</SUB>:<o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt; <SPAN class=SpellE>v<SUB>n</SUB></SPAN><o:p></o:p></SPAN></P></TD>
<TD class="" style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: medium none; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 153.55pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=205>
<P class=MsoNormal style="LINE-HEIGHT: 115%"><SPAN lang=EN-US style="mso-ansi-language: EN-US">x &gt;= <SPAN class=SpellE>v<SUB>n</SUB></SPAN><o:p></o:p></SPAN></P></TD></TR></TBODY></TABLE></DIV>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The choice whether we specify a LEFT or a RIGHT range ordering is basically an arbitrary one with only minor functional differences. But both have their pros and cons. In most scenarios a RIGHT range seems to be easier to formulate. On the other hand, a LEFT range function might be somewhat more intuitive to use when it comes to switching partitions in and out. We will come back to this topic later when talking about sliding window scenarios.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Also keep in mind that partition functions are not static. You can adjust the number of partitions at any time. By merging two partitions into one, you decrease the number by one, and by splitting one partition into two, you increase the number by one. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Partition Schemes</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Next, before starting to fill the partitions with data, we have to define where to store the partition data. This is being accomplished by means of a <B style="mso-bidi-font-weight: normal">Partition Scheme</B>. Each partition scheme is associated with a specific partition function, and for each partition defined by this function the filegroup where to store the data for this partition is being specified. A partition scheme is created using the following T-SQL syntax:<o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">CREATE PARTITION SCHEME</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> &lt;<I style="mso-bidi-font-style: normal">name</I>&gt; <B style="mso-bidi-font-weight: normal">AS PARTITION</B> &lt;<I style="mso-bidi-font-style: normal">partition function</I>&gt; <B style="mso-bidi-font-weight: normal">TO (</B>&lt;<I style="mso-bidi-font-style: normal">fg<SUB>1</SUB></I>&gt;<SPAN class=GramE>, …,</SPAN> &lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">fg<SUB>m</SUB></I></SPAN>&gt;<B style="mso-bidi-font-weight: normal">);</B></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">There has to be an assignment to a filegroup for each partition defined by the function, and the assignments have to be in order, i.e. partition<SUB>1</SUB> maps to fg<SUB>1</SUB>, and so on. But it’s also legitimate to specify more filegroups than partitions exist. In this case, the first filegroup in excess will be marked as NEXT USED (more on this later). All filegroups listed must already exist in the database. But the filegroups do not need to be distinct, i.e. several partitions can be mapped to the same filegroup. There’s even a special abbreviated syntax for the case where all partitions map to the same filegroup, <B style="mso-bidi-font-weight: normal">ALL TO (</B>&lt;<SPAN class=SpellE><SPAN class=GramE><I style="mso-bidi-font-style: normal">fg</I></SPAN></SPAN>&gt;<B style="mso-bidi-font-weight: normal">)</B>.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Creating Partitioned Tables</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now that we have everything in place, let’s create the partitioned table. There is no big difference from creating a non-partitioned table, except the ON clause at the end of the statement. While for a non-partitioned table we can specify a filegroup where the table should be created on (if nothing is specified, the table is being created on the default filegroup), for a partitioned table we simply specify the partition scheme together with the partitioning column. So, the T-SQL <I style="mso-bidi-font-style: normal">statement</I> for creating a partitioned table looks like:<o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">CREATE TABLE</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> &lt;<I style="mso-bidi-font-style: normal">name</I>&gt; <SPAN class=GramE><B style="mso-bidi-font-weight: normal">(</B> …</SPAN> <B style="mso-bidi-font-weight: normal">) ON</B> &lt;<I style="mso-bidi-font-style: normal">partition scheme</I>&gt; <B style="mso-bidi-font-weight: normal">(</B>&lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">col</I></SPAN>&gt;<B style="mso-bidi-font-weight: normal">)</B> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The partitioning column specified must be a column of the table (even computed columns are allowed as long as they are persisted) and it must be of the same type (or implicitly convertible to this type) defined for the partition function the partition scheme is associated with. Practically, this column is being defined as NOT NULL, although this is not a requirement. The same partition scheme can be used for other tables as well.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Partitioning Metadata</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now let’s have a closer look at the metadata associated with the various partition objects. SQL Server provides several system catalog views to make the internals of partitioning visible. For a comprehensive description of these catalog views please consult BOL. Here we are just focusing on the most meaningful columns of those views while following the creation process of a sample partition.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">So let’s start with creating a partition function for an integer column:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">FUNCTION</SPAN> PFTest <SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">int</SPAN><SPAN style="COLOR: gray">) </SPAN><SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">RANGE</SPAN> <SPAN style="COLOR: gray">RIGHT</SPAN> <SPAN style="COLOR: blue">FOR</SPAN> <SPAN style="COLOR: blue">VALUES</SPAN> <SPAN style="COLOR: gray">(</SPAN>10<SPAN style="COLOR: gray">,</SPAN> 20<SPAN style="COLOR: gray">,</SPAN> 30<SPAN style="COLOR: gray">,</SPAN> 40<SPAN style="COLOR: gray">)<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Every partition function has an entry in the <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_functions</B></SPAN> catalog view. The above sample partition function might create the following row:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">name</SPAN><SPAN style="COLOR: gray">,</SPAN> function_id<SPAN style="COLOR: gray">,</SPAN> fanout<SPAN style="COLOR: gray">,</SPAN> boundary_value_on_right<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>from</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: green">sys.partition_functions<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> <SPAN style="COLOR: blue">name</SPAN> <SPAN style="COLOR: gray">=</SPAN> N<SPAN style="COLOR: red">'PFTest'</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">name<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>function_id fanout<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>boundary_value_on_right<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">--------- ----------- ----------- -----------------------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>65546<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">function_id</I></SPAN> is a unique identifier assigned to each partition function. The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">fanout</I></SPAN> column specifies the number of partitions defined by this function (Note: this number is always the number of boundary values given in the partition function definition plus 1). And the value for <SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_value_on_right</I></SPAN> is 1 for RIGHT aligned partition ranges and is 0 for LEFT ones. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The data type the partition function is based on can be determined from the catalog view <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_parameters</B></SPAN>:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> parameter_id<SPAN style="COLOR: gray">,</SPAN> <SPAN style="COLOR: fuchsia">TYPE_NAME</SPAN><SPAN style="COLOR: gray">(</SPAN>system_type_id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [type]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_parameters<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>where</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> function_id <SPAN style="COLOR: gray">=</SPAN> 65546<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">parameter_id type<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">------------ ----------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Note that the partitioning catalog views are already prepared to deal with more than one partitioning column. But the current T&shy;&shy;-SQL syntax only allows <SPAN class=GramE>to create</SPAN> partitions based on a single partitioning column. Therefore, <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_parameters</B></SPAN> currently will only have one row per partition function and <SPAN class=SpellE><I style="mso-bidi-font-style: normal">parameter_id</I></SPAN> always will be 1.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">And finally, the <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_range_values</B></SPAN> catalog view has an entry for every boundary value given in the function definition:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> boundary_id, parameter_id<SPAN style="COLOR: gray">,</SPAN> <SPAN style="COLOR: blue">value<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys.partition_range_values<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> function_id <SPAN style="COLOR: gray">=</SPAN> 65546</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">boundary_id parameter_id value<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">----------- ------------ -----<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>20<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The boundary values specified in the CREATE PARTITION FUNCTION statement are assigned to <SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_id</I>’s</SPAN> in ascending order. Also note that the <I style="mso-bidi-font-style: normal">value</I> column is of type <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sql_variant</B></SPAN> having the base type of the partition function parameter, i.e. </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">SQL_VARIANT_PROPERTY</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">(</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">value</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">,</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: red">'BaseType'</SPAN><SPAN style="COLOR: gray">)</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"> should give the same type returned by the previous query on <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_parameters</B></SPAN>.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Before creating the partition scheme, we have to create the filegroups to hold each partition, in case they do not yet exist. It’s also legitimate to place all partitions in the same filegroup, but doing so would sacrifice much of the benefits partitioning does offer to you. For our sample partition scheme let’s create five filegroups named FG1, FG2, FG3, FG4 and FG5 using the ALTER DATABASE ADD FILEGROUP statement.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now we are ready to create the partition scheme based on our partition function and map each of the 5 partitions to one of our filegroups:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">SCHEME</SPAN> PSTest <SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">PARTITION</SPAN> PFTest <SPAN style="COLOR: blue">TO</SPAN> <SPAN style="COLOR: gray">(</SPAN>FG1<SPAN style="COLOR: gray">,</SPAN> FG2<SPAN style="COLOR: gray">,</SPAN> FG3<SPAN style="COLOR: gray">,</SPAN> FG4<SPAN style="COLOR: gray">,</SPAN> FG5<SPAN style="COLOR: gray">)</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">This creates an entry for the catalog view <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_schemes</B></SPAN> that can be queried like:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">name</SPAN><SPAN style="COLOR: gray">,</SPAN> data_space_id<SPAN style="COLOR: gray">,</SPAN> function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys.partition_schemes<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> <SPAN style="COLOR: blue">name</SPAN> <SPAN style="COLOR: gray">=</SPAN> N<SPAN style="COLOR: red">'PSTest'</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">name<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data_space_id function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">--------- ------------- -----------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>65608<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>65546</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">data_space_id</I></SPAN> uniquely identifies the data space that is associated with the partition scheme (a data space represents the storage scheme of a table/index and either can be a filegroup, or a partition scheme). And <SPAN class=SpellE><I style="mso-bidi-font-style: normal">function_id</I></SPAN> links the partition scheme with the partition function it is based on.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The data space of a partition scheme is further divided into destination data spaces where each destination data space is having an entry in the system catalog view <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.destination_data_spaces</B></SPAN>. Every destination data space is linked to its parent partition scheme through its <SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_scheme_id</I></SPAN> column. The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">data_space_id</I></SPAN> column links the destination data space to its pertaining filegroup. The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">destination_id</I></SPAN> is equivalent to the partition number the destination data space is mapped to. The following query returns each destination data space for our sample partition scheme and the filegroup assigned to it:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> dds<SPAN style="COLOR: gray">.</SPAN>destination_id<SPAN style="COLOR: gray">,</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [filegroup]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys.destination_data_spaces</SPAN> dds <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys.filegroups</SPAN> fg<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>data_space_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>partition_scheme_id <SPAN style="COLOR: gray">= </SPAN>65608</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">destination_id filegroup<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">-------------- ---------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FG1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FG2<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FG3<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FG4<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>FG5</SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Putting it all together</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In order to display all this information within a single query, I have created the following view that will be used extensively within the next sections:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<DIV class=Section1>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: #eeece1; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-yfti-tbllook: 1536; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-background-themecolor: background2; mso-border-insideh: none; mso-border-insidev: none" cellSpacing=0 cellPadding=0 border=0 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; WIDTH: 19cm; PADDING-TOP: 0cm" vAlign=top width=718>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">VIEW</SPAN> [dbo]<SPAN style="COLOR: gray">.</SPAN>[PartitionRanges] <SPAN style="COLOR: blue">AS<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> pf<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_function]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_scheme]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1 <SPAN style="COLOR: blue">as</SPAN> [partition_number]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>value <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: gray">NULL</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">'&lt;'</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [relation]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>value <SPAN style="COLOR: blue">as</SPAN> [boundary_value]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: fuchsia">type_name</SPAN><SPAN style="COLOR: gray">(</SPAN>pp<SPAN style="COLOR: gray">.</SPAN>system_type_id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [type]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>fg<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [filegroup]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: gray">NULL</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">N'IN USE'</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [status]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_functions</SPAN> pf<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_parameters</SPAN> pp <SPAN style="COLOR: blue">on</SPAN> pp<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_schemes</SPAN> ps <SPAN style="COLOR: blue">on</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">destination_data_spaces</SPAN> dds<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>partition_scheme_id <SPAN style="COLOR: gray">=</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">and</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>destination_id <SPAN style="COLOR: gray">=</SPAN> 1&nbsp;<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">filegroups</SPAN> fg <SPAN style="COLOR: blue">on</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>data_space_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_range_values</SPAN> prv<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">and</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>parameter_id <SPAN style="COLOR: gray">=</SPAN> 1 <SPAN style="COLOR: gray">and<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>boundary_id <SPAN style="COLOR: gray">=</SPAN> 1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>boundary_value_on_right <SPAN style="COLOR: gray">=</SPAN> 1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">union</SPAN> <SPAN style="COLOR: gray">all<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> pf<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_function]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_scheme]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>boundary_id <SPAN style="COLOR: gray">+</SPAN> <SPAN style="COLOR: fuchsia">cast</SPAN><SPAN style="COLOR: gray">(</SPAN>pf<SPAN style="COLOR: gray">.</SPAN>boundary_value_on_right <SPAN style="COLOR: blue">as</SPAN> <SPAN style="COLOR: blue">int</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [partition_number]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>boundary_value_on_right <SPAN style="COLOR: gray">=</SPAN> 0 <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: red">'&lt;='</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">'&gt;='</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [relation]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>prv<SPAN style="COLOR: gray">.</SPAN>value <SPAN style="COLOR: blue">as</SPAN> [boundary_value]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: fuchsia">type_name</SPAN><SPAN style="COLOR: gray">(</SPAN>pp<SPAN style="COLOR: gray">.</SPAN>system_type_id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [type]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>fg<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [filegroup]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: gray">NULL</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">N'IN USE'</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [status]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_functions</SPAN> pf<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_range_values</SPAN> prv <SPAN style="COLOR: blue">on<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">and</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>parameter_id <SPAN style="COLOR: gray">=</SPAN> 1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_parameters</SPAN> pp <SPAN style="COLOR: blue">on</SPAN> pp<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_schemes</SPAN> ps <SPAN style="COLOR: blue">on</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">destination_data_spaces</SPAN> dds<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>partition_scheme_id <SPAN style="COLOR: gray">=</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">and<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dds<SPAN style="COLOR: gray">.</SPAN>destination_id <SPAN style="COLOR: gray">=</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>boundary_id <SPAN style="COLOR: gray">+</SPAN> <SPAN style="COLOR: fuchsia">cast</SPAN><SPAN style="COLOR: gray">(</SPAN>pf<SPAN style="COLOR: gray">.</SPAN>boundary_value_on_right <SPAN style="COLOR: blue">as</SPAN> <SPAN style="COLOR: blue">int</SPAN><SPAN style="COLOR: gray">)<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">filegroups</SPAN> fg <SPAN style="COLOR: blue">on</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>data_space_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">union</SPAN> <SPAN style="COLOR: gray">all<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> pf<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_function]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_scheme]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>pf<SPAN style="COLOR: gray">.</SPAN>fanout <SPAN style="COLOR: blue">as</SPAN> [partition_number]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>value <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: gray">NULL</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">'&gt;'</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [relation]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>value <SPAN style="COLOR: blue">as</SPAN> [boundary_value]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: fuchsia">type_name</SPAN><SPAN style="COLOR: gray">(</SPAN>pp<SPAN style="COLOR: gray">.</SPAN>system_type_id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [type]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>fg<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [filegroup]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: gray">is</SPAN> <SPAN style="COLOR: gray">null</SPAN> <SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: gray">NULL</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">N'IN USE'</SPAN> <SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [status]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_functions</SPAN> pf<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_parameters</SPAN> pp <SPAN style="COLOR: blue">on</SPAN> pp<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_schemes</SPAN> ps <SPAN style="COLOR: blue">on</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">destination_data_spaces</SPAN> dds<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>partition_scheme_id <SPAN style="COLOR: gray">=</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">and</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>destination_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>fanout&nbsp;<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">filegroups</SPAN> fg <SPAN style="COLOR: blue">on</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>data_space_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">left</SPAN> <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_range_values</SPAN> prv<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">and</SPAN> prv<SPAN style="COLOR: gray">.</SPAN>parameter_id <SPAN style="COLOR: gray">=</SPAN> 1 <SPAN style="COLOR: gray">and<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>prv<SPAN style="COLOR: gray">.</SPAN>boundary_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>fanout <SPAN style="COLOR: gray">-</SPAN> 1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>boundary_value_on_right <SPAN style="COLOR: gray">=</SPAN> 0<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">union</SPAN> <SPAN style="COLOR: gray">all<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> pf<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_function]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_scheme]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">NULL,</SPAN> <SPAN style="COLOR: gray">NULL,</SPAN> <SPAN style="COLOR: gray">NULL,</SPAN> <SPAN style="COLOR: gray">NULL,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>fg<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [filegroup]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">case</SPAN> <SPAN style="COLOR: blue">when</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>destination_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>fanout <SPAN style="COLOR: gray">+</SPAN> 1<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">then</SPAN> <SPAN style="COLOR: red">N'NEXT USED'</SPAN> <SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: red">N'NOT USED'<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">end</SPAN> <SPAN style="COLOR: blue">as</SPAN> [status]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_functions</SPAN> pf<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_schemes</SPAN> ps <SPAN style="COLOR: blue">on</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>function_id <SPAN style="COLOR: gray">=</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>function_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">destination_data_spaces</SPAN> dds<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>partition_scheme_id <SPAN style="COLOR: gray">=</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">and<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dds<SPAN style="COLOR: gray">.</SPAN>destination_id <SPAN style="COLOR: gray">&gt;</SPAN> pf<SPAN style="COLOR: gray">.</SPAN>fanout<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">filegroups</SPAN> fg <SPAN style="COLOR: blue">on</SPAN> fg<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> dds<SPAN style="COLOR: gray">.</SPAN>data_space_id</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P></TD></TR></TBODY></TABLE></DIV>
<DIV class=Section1>&nbsp;</DIV>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">To watch this view working, simply execute:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">SELECT</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: gray">*</SPAN> <SPAN style="COLOR: blue">FROM</SPAN> PartitionRanges <SPAN style="COLOR: blue">WHERE</SPAN> partition_function <SPAN style="COLOR: gray">=</SPAN> N<SPAN style="COLOR: red">'PFTest'</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>20<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As one can see, this view returns a row for every partition defined by the partition function together with the range of values covered by this partition and the filegroup the partition is mapped to by the partition scheme. If there is any filegroup assigned in the partition scheme currently not mapped to any partition, it will also be shown together with its status, e.g. NEXT USED.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Performing Alterations on Partitions</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Next we will perform modifications on the partition function and study the changes to the metadata. The two possible modifications of a partition function are the deletion of a partition by merging two adjacent partition ranges into one, and the creation of a new partition by splitting one existent partition into two. This is being accomplished by the two variants of the ALTER PARTITION FUNCTION statement.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The first one we are investigating in is the MERGE. The syntax is: <o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">ALTER PARTITION FUNCTION</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> &lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_function_name</I></SPAN>&gt; <B style="mso-bidi-font-weight: normal">() MERGE RANGE (</B>&lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_value</I></SPAN>&gt;<B style="mso-bidi-font-weight: normal">);</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_value</I></SPAN> has to be one of those already stored in <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_range_values</B></SPAN> for this partition function.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">If we perform the following MERGE <SPAN class=GramE>operation on our sample partition function</SPAN>:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">ALTER</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">FUNCTION</SPAN> PFTest<SPAN style="COLOR: gray">()</SPAN> <SPAN style="COLOR: blue">MERGE</SPAN> <SPAN style="COLOR: blue">RANGE</SPAN> <SPAN style="COLOR: gray">(</SPAN>20<SPAN style="COLOR: gray">)<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN class=GramE><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN class=GramE><SPAN lang=EN-US style="mso-ansi-language: EN-US">and</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"> then check again the results of our <SPAN class=SpellE>PartionRanges</SPAN> view, we’re getting:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As one can <SPAN class=GramE>see,</SPAN> the former partition 3, which had been mapped to filegroup FG3, has been removed and partition 2 now covers the range between 10 and 30, i.e. the dropped partition has been merged with its predecessor partition. This is true because our partition function was defined as a RANGE RIGHT function. For a RANGE LEFT function the partition would have been merged with its successor partition. Since we have not yet partitioned any table using this partition scheme, no real data have been moved by the merge. But otherwise, all data that would have been placed in partition 3 prior to the <SPAN class=GramE>merge,</SPAN> would have to be moved from FG3 to FG2 during the merge. Obviously, that is something that should be avoided for big partitions. Therefore, usually we only merge partitions that are already empty. Later we will see how a partition easily can be emptied by switching partitions out.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">But, how do we drop partition 1? Because, if we specify for the boundary value in the MERGE statement the lowest possible value, which is 10,<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>partition 2 will be dropped, and not partition 1. The answer is<SPAN class=GramE>,</SPAN> you can’t drop partition 1 if the partition function defines a RANGE RIGHT partition. Therefore, when having the need to regularly switch out the partition with the oldest data, as in a sliding window scenario, and the partition function is defined as RANGE RIGHT, partition 1 should be an empty partition, not containing any data. Hence, when defining the partition scheme we can specify any filegroup, like PRIMARY, for the empty first partition as it never should receive any data.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Because of this, you might argue that RANGE RIGHT partitions are not the best choice for sliding window scenarios. But stay tuned. We will discover a similar problem for LEFT RANGE partitions, just on the opposite end.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now let’s inspect the effects of the other operation on partition functions, the SPLIT. The syntax is: <o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">ALTER PARTITION FUNCTION</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> &lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_function_name</I></SPAN>&gt; <B style="mso-bidi-font-weight: normal">() SPLIT RANGE (</B>&lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_value</I></SPAN>&gt;<B style="mso-bidi-font-weight: normal">);</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The <SPAN class=SpellE><I style="mso-bidi-font-style: normal">boundary_value</I></SPAN> must be a new one, i.e. not yet existing in <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_range_values</B></SPAN> for this partition function, and the data type of the new boundary value must be implicitly convertible to the type of the partition function parameter.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As the name implies, a SPLIT operation splits an existing partition range into two ranges. All the existing data that fall into the new range have to physically move into the new partition. Again, this should be avoided for big partitions by enforcing that none of the existing data rows falls into the new range, e.g.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN class=GramE>by</SPAN> means of a CHECK CONSTRAINT. Also <SPAN class=GramE>note,</SPAN> that even if no data are being moved, the filegroup mapped to the partition to be split must not be designated as READ_ONLY.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Another thing we have to make sure before performing the SPLIT, is that a filegroup marked as NEXT USED exists for all partition schemes based on the partition function that we’d like to split. The new partition being created by the SPLIT implicitly will be mapped to this NEXT USED filegroup. If such a filegroup does not yet exist for a partition scheme, you can create one using the following T-SQL statement:<o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">ALTER PARTITION SCHEME</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> &lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_scheme_name</I></SPAN>&gt; <B style="mso-bidi-font-weight: normal">NEXT USED</B> &lt;<SPAN class=SpellE><I style="mso-bidi-font-style: normal">filegroup_name</I></SPAN>&gt;<B style="mso-bidi-font-weight: normal">;</B><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">You can also designate a NEXT USED filegroup in the CREATE PARTITION SCHEME statement by listing more filegroups than partitions exist. In this case, the first filegroup not mapped to a partition will be marked as NEXT USED.&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In our previous MERGE example we have removed filegroup FG3 from the partition scheme. So let’s mark this one as our NEXT USED filegroup:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">ALTER</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">SCHEME</SPAN> PSTest <SPAN style="COLOR: blue">NEXT</SPAN> USED FG3</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Again, let’s see the effect of this statement by querying our <SPAN class=SpellE>PartitionRanges</SPAN> view. Here’s the result:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL FG3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NEXT USED</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As one can see, the partition scheme now has filegroup FG3 designated as the NEXT USED filegroup.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now we are able to issue a SPLIT operation on our partition function. Here’s the statement we’d like to execute:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">ALTER</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">FUNCTION</SPAN> PFTest<SPAN style="COLOR: gray">()</SPAN> SPLIT <SPAN style="COLOR: blue">RANGE</SPAN> <SPAN style="COLOR: gray">(</SPAN>50<SPAN style="COLOR: gray">)</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">This statement splits the existing partition range for values &gt;= 40 into the range &gt;= 40 and &lt; 50 and the range &gt;= 50 and thus adds an additional partition at the right end of our partition ranges. Again, let’s verify this using the <SPAN class=SpellE>PartitionRanges</SPAN> view:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>50<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Previously, I mentioned that we also might run into troubles removing the outmost partition with a LEFT RANGE partition function. So let’s create another RANGE LEFT partition function together with a partition scheme and see what might be the effect of adding a partition at the right end. Here are the statements to create the function and scheme:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">FUNCTION</SPAN> PFTestL <SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: blue">int</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">RANGE</SPAN> <SPAN style="COLOR: gray">LEFT</SPAN> <SPAN style="COLOR: blue">FOR</SPAN> <SPAN style="COLOR: blue">VALUES</SPAN> <SPAN style="COLOR: gray">(</SPAN>10<SPAN style="COLOR: gray">,</SPAN> 20<SPAN style="COLOR: gray">,</SPAN> 30<SPAN style="COLOR: gray">)<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">GO<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">SCHEME</SPAN> PSTestL <SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">PARTITION</SPAN> PFTestL <SPAN style="COLOR: blue">TO</SPAN> <SPAN style="COLOR: gray">(</SPAN>FG1<SPAN style="COLOR: gray">,</SPAN> FG2<SPAN style="COLOR: gray">,</SPAN> FG3<SPAN style="COLOR: gray">,</SPAN> FG4<SPAN style="COLOR: gray">,</SPAN> FG5<SPAN style="COLOR: gray">)<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">GO<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">SELECT</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: gray">*</SPAN> <SPAN style="COLOR: blue">FROM</SPAN> PartitionRanges <SPAN style="COLOR: blue">WHERE</SPAN> function_name <SPAN style="COLOR: gray">=</SPAN> N<SPAN style="COLOR: red">'PFTestL'</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>20<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;</SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NEXT USED</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Note, that we already have created a NEXT USED filegroup in the CREATE PARTITION SCHEME statement by specifying more filegroups than required by the underlying partition function. Now let’s see the effect of splitting the rightmost partition by running the following statement and looking at our <SPAN class=SpellE>PartionRanges</SPAN> view output:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">ALTER</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">FUNCTION</SPAN> PFTestL<SPAN style="COLOR: gray">()</SPAN> SPLIT <SPAN style="COLOR: blue">RANGE</SPAN> <SPAN style="COLOR: gray">(</SPAN>40<SPAN style="COLOR: gray">)</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">partition_function partition_scheme partition_number relation boundary_value type filegroup status<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">------------------ ---------------- ---------------- -------- -------------- ---- --------- ---------<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>20<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>30<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;=<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE<BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">PFTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTestL<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&gt;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FG4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN USE</SPAN><o:p>&nbsp;</o:p></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As you can see, the new partition has been inserted logically between partition 3 and the previous partition 4, and all the rows from previous partition 4 with values &gt; 30 and &lt;= 40 would have been moved into the new partition 4, i.e. from filegroup FG4 to filegroup FG5. Thus, with a LEFT RANGE partition function you can’t add a new partition at the right end. The answer to this dilemma again is the use of an empty partition at the high end of the partition range when using a LEFT RANGE partition function.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Therefore, the general advice, when defining the partition scheme for a sliding window scenario, is to keep the first partition, for RIGHT RANGE partition functions, or respectively the last partition, for LEFT RANGE partition functions, empty and to map this partition in the partition scheme to a special filegroup, like PRIMARY, in order to make your intention, to keep this partition empty, more clear. Additionally, a CHECK CONSTRAINT can be defined to enforce this requirement.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Hence, in our previous examples the partition schemes should have been defined the following way, if they are intended to be used in a sliding window scenario:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">SCHEME</SPAN> PSTest <SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">PARTITION</SPAN> PFTest <SPAN style="COLOR: blue">TO</SPAN> <SPAN style="COLOR: gray">([PRIMARY], </SPAN>FG1<SPAN style="COLOR: gray">,</SPAN> FG2<SPAN style="COLOR: gray">,</SPAN> FG3<SPAN style="COLOR: gray">,</SPAN> FG4<SPAN style="COLOR: gray">)</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">PARTITION</SPAN> <SPAN style="COLOR: blue">SCHEME</SPAN> PSTestL <SPAN style="COLOR: blue">AS</SPAN> <SPAN style="COLOR: blue">PARTITION</SPAN> PFTestL <SPAN style="COLOR: blue">TO</SPAN> <SPAN style="COLOR: gray">(</SPAN>FG1<SPAN style="COLOR: gray">,</SPAN> FG2<SPAN style="COLOR: gray">,</SPAN> FG3<SPAN style="COLOR: gray">,</SPAN> <SPAN style="COLOR: gray">[PRIMARY], </SPAN>FG4<SPAN style="COLOR: gray">)</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN class=GramE><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN class=GramE><SPAN lang=EN-US style="mso-ansi-language: EN-US">Note,</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"> that if we specify a NEXT USED filegroup in the partition scheme creation statement for a LEFT RANGE partition function, this filegroup mapping has to appear after the mapping for the empty partition. Therefore, in the second example, the NEXT USED filegroup FG4 has to come after PRIMARY. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Partitions and Allocation Units</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">So far we have covered all the basics about partitioning. We have seen how to define the partition ranges using a partition function and how to map a filegroup to each partition using a partition scheme. Next, I will talk about the effects on the metadata when partitioning a table or an index.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes"></SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">First, let’s create a table and partition this table based on the partition scheme <SPAN class=SpellE>PSTest</SPAN> defined earlier. We want to make the table definition fairly simple. The table just consists of a unique key column and the column we want the table to be partitioned on. Here’s the table definition:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">TABLE</SPAN> TabTest <SPAN style="COLOR: gray">(</SPAN>pk <SPAN style="COLOR: blue">uniqueidentifier</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null,</SPAN> pc <SPAN style="COLOR: blue">int</SPAN> <SPAN style="COLOR: gray">not</SPAN> <SPAN style="COLOR: gray">null)</SPAN> <SPAN style="COLOR: blue">ON</SPAN> PSTest<SPAN style="COLOR: gray">(</SPAN>pc<SPAN style="COLOR: gray">)<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now, let’s explore the changes introduced into the metadata by creating this partitioned table. Every table/index has a data space assigned. As we have seen, a data space either can be a filegroup, or a partition scheme. The <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.indexes</B></SPAN> row for the table has a column <SPAN class=SpellE><I style="mso-bidi-font-style: normal">data_space_id</I></SPAN> which you can use to join <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.indexes</B></SPAN> with the system catalog view <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.data_spaces</B></SPAN>. Here you can query the <I style="mso-bidi-font-style: normal">type</I> column to see if the data space refers to a filegroup, if the value is ‘FG’, or to a partition scheme, if the value is ‘PS’. But if you know in advance that you are dealing with a partition scheme, you’d better join with <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partition_schemes</B></SPAN>, because this derived view returns only the subset of <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.data_spaces</B></SPAN> where type is ‘PS’, augmented with the ID of the partition function the scheme is based on.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In order to determine the partitioning column, one has to look in the <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.index_columns</B></SPAN> view for rows pertaining to this <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.indexes</B></SPAN> entry and <SPAN class=GramE>having<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>a</SPAN> non-zero <SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_ordinal</I></SPAN> value. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Given that, the following query returns all partitioned tables and indexes together with the partition scheme and the partitioning column:</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: fuchsia">object_name</SPAN><SPAN style="COLOR: gray">(</SPAN>i<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [table_name]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>i<SPAN style="COLOR: gray">.</SPAN>index_id<SPAN style="COLOR: gray">,</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>name <SPAN style="COLOR: blue">as</SPAN> [partition_scheme]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: fuchsia">col_name</SPAN><SPAN style="COLOR: gray">(</SPAN>i<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN><SPAN style="COLOR: gray">,</SPAN> ic<SPAN style="COLOR: gray">.</SPAN>column_id<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [partitioning_column]<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">indexes</SPAN> i<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partition_schemes</SPAN> ps<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> ps<SPAN style="COLOR: gray">.</SPAN>data_space_id <SPAN style="COLOR: gray">=</SPAN> i<SPAN style="COLOR: gray">.</SPAN>data_space_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">index_columns</SPAN> ic<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> ic<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN> <SPAN style="COLOR: gray">=</SPAN> i<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN> <SPAN style="COLOR: gray">and</SPAN> ic<SPAN style="COLOR: gray">.</SPAN>index_id <SPAN style="COLOR: gray">=</SPAN> i<SPAN style="COLOR: gray">.</SPAN>index_id <SPAN style="COLOR: gray">and<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ic<SPAN style="COLOR: gray">.</SPAN>partition_ordinal <SPAN style="COLOR: gray">&gt;</SPAN> 0</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">table_name index_id<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>partition_scheme partitioning_column<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">---------- ----------- ---------------- -------------------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>PSTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>pc</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Next, we’d like to enter data into the partitioned table. But before doing so, we have to create database files within each of the filegroups defined for the partition scheme. Just add a secondary data file to each of the 5 filegroups we have created previously. For our purpose it’s not important how big those files are and which drive they are placed on. But in practice it deserves some careful planning to specify a file size big enough to avoid auto-grow and small enough to avoid wasting precious disk space. Therefore you need some good estimates on the expected maximum partition size. Also, for optimal performance, it would be beneficial to place each of the files on a separate physical disk.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">After having created the disk files, we should enter a few rows in our sample table such that each partition has at least 1 row. But leave the first partition empty, as later we want to use this table for demonstrating a sliding window process (as we have seen in the previous section, for a RANGE RIGHT partition function, the first partition should be left empty).</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">After having filled the partitions with data, we’d like <SPAN class=GramE>to<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>see</SPAN> how the data are being distributed over the partitions. Again, there are several system catalog views available to make this information visible. First there is the view <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.partitions</B></SPAN><B style="mso-bidi-font-weight: normal">,</B> providing an entry for every partition defined in the database (<SPAN class=GramE>note, that</SPAN> even non-partitioned tables consist of one partition). This entry contains the <SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_number</I></SPAN>, the number of rows within this partition and the <SPAN class=SpellE><I style="mso-bidi-font-style: normal">hobt_id</I></SPAN> column, which you can join with the <SPAN class=SpellE><I style="mso-bidi-font-style: normal">container_id</I></SPAN> column of the <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.allocation_units</B></SPAN> view. Each partition can consist of up to three allocation units, for in-row data, LOB data and row-overflow data. From the <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.allocation_units</B></SPAN> view you can gain information about the number of pages allocated for each allocation unit. If you also want to retrieve information about the actual pages allocated, you’d better join with the undocumented <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.system_internals_allocation_units</B></SPAN> view instead of <SPAN class=SpellE><B style="mso-bidi-font-weight: normal">sys.allocation_units</B></SPAN>, because this view additionally returns the <SPAN class=SpellE><I style="mso-bidi-font-style: normal">first_page</I></SPAN>, <SPAN class=SpellE><I style="mso-bidi-font-style: normal">root_page</I></SPAN> and <SPAN class=SpellE><I style="mso-bidi-font-style: normal">first_iam_page</I></SPAN> values for traversing the page chain or index tree.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In order to get this information for our sample table, you can issue the following select statement and get these results returned:&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">select</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: fuchsia">object_name</SPAN><SPAN style="COLOR: gray">(</SPAN>p<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN><SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">as</SPAN> [table_name]<SPAN style="COLOR: gray">,</SPAN> p<SPAN style="COLOR: gray">.</SPAN>index_id<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>p<SPAN style="COLOR: gray">.</SPAN>partition_number<SPAN style="COLOR: gray">,</SPAN> p<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: blue">rows</SPAN><SPAN style="COLOR: gray">,</SPAN> au<SPAN style="COLOR: gray">.</SPAN>total_pages <SPAN style="COLOR: blue">as</SPAN> [pages]<SPAN style="COLOR: gray">,<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>au<SPAN style="COLOR: gray">.</SPAN>type_desc <SPAN style="COLOR: blue">as</SPAN> [allocation_type]<SPAN style="COLOR: gray">,</SPAN> au<SPAN style="COLOR: gray">.</SPAN>first_page<SPAN style="COLOR: gray">,</SPAN> au<SPAN style="COLOR: gray">.</SPAN>root_page<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="COLOR: blue">from</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">partitions</SPAN> p <SPAN style="COLOR: gray">join</SPAN> <SPAN style="COLOR: green">sys</SPAN><SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: green">system_internals_allocation_units</SPAN> au<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">on</SPAN> au<SPAN style="COLOR: gray">.</SPAN>container_id <SPAN style="COLOR: gray">=</SPAN> p<SPAN style="COLOR: gray">.</SPAN>hobt_id<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">where</SPAN> p<SPAN style="COLOR: gray">.</SPAN><SPAN style="COLOR: fuchsia">object_id</SPAN> <SPAN style="COLOR: gray">=</SPAN> <SPAN style="COLOR: fuchsia">object_id</SPAN><SPAN style="COLOR: gray">(</SPAN><SPAN style="COLOR: red">N'TabTest'</SPAN><SPAN style="COLOR: gray">)</SPAN></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">table_name index_id partition_number rows<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>pages<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>allocation_type first_page<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>root_page<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">---------- -------- ---------------- ------ ------ --------------- -------------- --------------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x000000000000 0x000000000000<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x080000000400 0x000000000000<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x080000000500 0x000000000000<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x080000000600 0x000000000000<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x080000000700 0x000000000000</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As you can see, our table has 5 partitions. Partition 1 has no data allocated and all other partitions are having 1 allocation unit assigned for in-row data pages, consisting of 2 pages (1 data and 1 IAM page). Since our table still is a heap, the root page pointer is NULL.&nbsp;</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Partitioned Indexes</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In the next section we will have a closer look at partitioned indexes. Besides partitioning tables, you may also partition indexes. Partitioning an index transforms the single B-tree of a non-partitioned index into several smaller B-trees, one for each partition defined by the partition function, where each B-tree only consists of index rows where the partitioning column falls into the partition’s range. Therefore, the partitioning column always has to be part of a partitioned index.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Splitting a partitioned index into several independent B-trees obviously also has consequences for index seeks. As long as the partitioning column is one of the search predicates, the optimizer knows which of the trees to choose for the index seek. But if the filter criteria do not include the partitioning column, the optimizer would not know where to start the index seek or scan when using a partitioned index. E.g. if we create the following composite partitioned clustered index “CREATE CLUSTERED INDEX <SPAN class=SpellE>IX_Tab</SPAN> ON Tab (a, b)”, where table Tab is being partitioned on column b, the query “SELECT * FROM Tab WHERE a = @x” cannot be performed as a simple clustered index seek, like in the non-partitioned case, but each of the index trees would have to be traversed separately to find the qualifying records. As this example shows, for partitioned tables the rule, that the table rows are sorted by the clustered index keys, does not necessarily hold true for the whole table, but only for single partitions. Therefore, it’s always good practice to include the partitioning column in your search predicates, even if it does not affect the result set.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">&nbsp;</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">If an index is partitioned on the same column as its base table and the partition scheme used is based on the same partition function used for partitioning the table, both table and index are said to be aligned. If you do not specify otherwise, an index is automatically aligned with its table. A clustered index always has to be aligned with its base table. In fact, if you create the clustered index differently, the underlying table will adopt the allocation scheme of the clustered index. Thus, to enforce a new allocation scheme for a table, just rebuild the clustered index with the new scheme. Therefore, the easiest way to partition an existing table is to create a partitioned clustered index on the table, although, it might not be the most efficient way doing so.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Having all indexes aligned with its base table is essential for switching table partitions in and out, as we’ll see later. But it’s also legal to partition an index on a different partitioning column or using a different partition function with a different number of partitions or different boundary values.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>You may also create an index, that is not partitioned, on a partitioned table, or partition an index although the base table isn’t partitioned. If you want to apply a different allocation scheme on the index, just use the ON clause in the index creation statement just like for the table creation statement.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As we have seen, a partitioned index always has to include <SPAN class=GramE>it’s</SPAN> partitioning column. There are a few rules to be aware of concerning the inclusion of the partitioning column:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<DIV class=Section1>
<UL>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">For every unique index (also implies primary key and unique constraints), the partitioning column must be part of its index keys.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">For a non-unique clustered index, that does not contain the partitioning column, that column implicitly is being added to the index keys.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">For a non-unique <SPAN class=SpellE>nonclustered</SPAN> index, that does not include the partitioning <SPAN class=GramE>column,</SPAN> the partitioning column is added at the leaf level as a non-key column. <o:p></o:p></SPAN></DIV></LI></UL></DIV>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The major consequence is, that you cannot partition <SPAN class=GramE>an</SPAN> unique index on a column that is not one of the index keys. Therefore, if you need <SPAN class=GramE>an</SPAN> unique index or constraint to enforce the uniqueness of a set of columns, that does not include the partitioning column, it will be necessary to make the unique index a non-partitioned one, or find other ways to check for uniqueness.&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now let’s create two indexes on our sample table, a clustered one on the partitioning column and a primary key constraint on column <SPAN class=SpellE>pk</SPAN>, which is not partitioned:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">CREATE</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">CLUSTERED</SPAN> <SPAN style="COLOR: blue">INDEX</SPAN> CIX_TabTest <SPAN style="COLOR: blue">ON</SPAN> TabTest <SPAN style="COLOR: gray">(</SPAN>pc<SPAN style="COLOR: gray">)<BR></SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">GO<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">ALTER</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"> <SPAN style="COLOR: blue">TABLE</SPAN> TabTest <SPAN style="COLOR: blue">ADD</SPAN> <SPAN style="COLOR: blue">CONSTRAINT</SPAN> PK_TabTest <SPAN style="COLOR: blue">PRIMARY</SPAN> <SPAN style="COLOR: blue">KEY</SPAN> <SPAN style="COLOR: gray">(</SPAN>pk<SPAN style="COLOR: gray">)</SPAN> <SPAN style="COLOR: blue">ON</SPAN> FG1</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">And with query from the previous chapter we can inspect again the allocations:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes"></SPAN>&nbsp;</P>
<P class=MsoNormal style="mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">table_name index_id partition_number rows<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>pages<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>allocation_type first_page<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>root_page<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">---------- -------- ---------------- ------ ------ --------------- -------------- --------------<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x000000000000 0x000000000000<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x0B0000000400 0x0B0000000400<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>3<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x0B0000000500 0x0B0000000500<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>4<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x0B0000000600 0x0B0000000600<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>5<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>10<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x0B0000000700 0x0B0000000700<BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-no-proof: yes">TabTest<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>40<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>2<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IN_ROW_DATA<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>0x100000000300 0x100000000300</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">As you can see the clustered index is partitioned the same way as its base table and is spread over the partitions 2 through 5, with a separate index root page on every partition. Thus, the one clustered index is divided into 4 separate B-trees. Whereas the index for the primary key (<SPAN class=SpellE>index_id</SPAN> = 2) is not partitioned. But at the leaf level this index still has the partitioning column included as this is the clustering key, and therefore, when performing the bookmark lookup to get to the data page, SQL Server immediately knows in which partition to look for.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Sliding Window Scenario</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">One of the major benefits of partitioning is the ability to efficiently move chunks of data in and out of a table. If the chunks happen to be multiples of a partition, no data physically have to be moved, and only metadata for allocations have to be adjusted. This fact is being exploited in sliding window scenarios where on a regular basis (e.g. quarterly, monthly, weekly, or even daily) aged data are being moved out of a table, e.g. for archiving,<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>and new data swapped in, that up to this point have been accumulated in a staging table. By collecting the data in a staging table instead of inserting directly into the target table, one can take advantage of the fact, that bulk copying data into an empty staging table with no indexes in place is much more efficient than inserting data directly into a big table with all indexes in place. (See “SQL Server 2000 Incremental Bulk Load Case Study” in <A href="https://technet.microsoft.com/library/cc917716.aspx">https://technet.microsoft.com/library/cc917716.aspx</A>, which is equally applicable to SQL Server 2005 and later).<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">A typical requirement for a sliding window scenario might look like this:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<UL>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">The last 12 month of business transaction data should be stored in a partitioned fact table of a relational data warehouse.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">During each month, the current transaction data from various sources, e.g. the OLTP databases at each business site, are being collected within a staging table of the data warehouse.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">On the first of each month, all data older than 12 month should be <SPAN class=GramE>archived<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>and</SPAN> the data of<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>the previous month should be transferred from the staging table into the fact table.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></DIV></LI></UL>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">To put these requirements into reality, we first have to build the partitioned fact table. Either we build that table up from scratch by adding one partition each month until we have reached the final size of 12 month worth of data, or we have the data already available somewhere else, let’s say in a non-partitioned table, and simply have to transition this table into a partitioned table (e.g. by creating a new partitioned clustered index on the table). Either way, we first have to decide on how to distribute the 12 partitions over our storage media. Ideally, we devote one filegroup for every partition. Next, the 12 filegroups have to be spread over the available disk drives. Let’s say 4 drives are available, so we assign each of the filegroups in a round robin fashion to one of the drives by creating a secondary data file for the filegroup on this drive. The files should be sized big enough to hold one month of data plus some room for future growth. Creating the partition function is straight forward. Just define the 12 boundary values, being either the first day or the last day of each month, depending on whether we plan to create a RIGHT or LEFT range function. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now having the previous 12 month data within the partitioned table, let’s start the preparation work for the next month. We need another filegroup with a data file assigned where we create the non-partitioned staging table. Filling this staging table can be a continuous process during the month, inserting each days transactions at the end of the day, or the staging table is being filled with data at the end of the month (for alternative load scenarios also see the SQL Server Best Practices article “Loading Bulk Data into a Partitioned Table” in <A href="https://technet.microsoft.com/library/cc966380.aspx">https://technet.microsoft.com/library/cc966380.aspx</A>). Nevertheless, the staging table needs to have the same structure as the partitioned table. Whether you add the same indexes to the staging table already at the beginning or after filling the table with <SPAN class=GramE>data,</SPAN> depends on the usage of the staging table during the month. If you just insert new data, for optimal bulk insert performance, you should refrain from creating the indexes before all data have been loaded into the table. But, if the staging table already participates in queries, some indexes might be essential. Anyway, before merging the staging table with the partitioned table, the staging table must have the same indexes and foreign key constraints as the partitioned table and a check constraint must be defined on the partitioning <SPAN class=GramE>column, that</SPAN> restricts the data in the staging table to values conformant with the boundaries of new partition that will absorb the data.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now we have reached the end of the month and during the coming night the staging table’s data need to be moved into the partitioned table, so that this month’s data is available at the beginning of next business day for starting various data analysis jobs. We start with preparing the staging table. We create all the necessary indexes and foreign key constraints and define a check constraint for the partitioning column. Afterwards, we might try to shrink the file(s) associated with the staging table’s filegroup and run a final defragmentation on the staging table. Finally, it also might be a good idea checking the consistency of the table by running a DBCC CHECKTABLE. Now the time has come to move the data.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The essential operation to perform this data movement is the partition switch operation. In T-SQL this is being accomplished by the ALTER TABLE…SWITCH statement. The syntax is:<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">ALTER TABLE</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"> <SPAN class=SpellE><I style="mso-bidi-font-style: normal">source_table_name</I></SPAN> <B style="mso-bidi-font-weight: normal">SWITCH</B> [<B style="mso-bidi-font-weight: normal">PARTITION</B> <SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_out</I></SPAN>]</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><B style="mso-bidi-font-weight: normal">TO</B> <SPAN class=SpellE><I style="mso-bidi-font-style: normal">target_table_name</I></SPAN> [<B style="mso-bidi-font-weight: normal">PARTITION</B> <SPAN class=SpellE><I style="mso-bidi-font-style: normal">partition_in</I></SPAN>]<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">This statement supports three different scenarios:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<UL>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">You can move a partition of a partitioned table out into a non-partitioned table</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">You can move a non-partitioned table into a partition of a partitioned table</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">You can move a partition of one partitioned table into a partition of another partitioned table</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></DIV></LI></UL>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">All participating tables need to be structurally equivalent, i.e. need to have the same columns, same clustered index, etc. The target table/partition must be empty, and source and target partition must reside in the same filegroup. If the switch target is a partitioned table, all indexes on this table have to be aligned with the table. Any non-aligned index has to be dropped or disabled prior to the switch operation. For an exact list of requirements see the topic ‘Transferring Data Efficiently by Using Partition Switching’ in SQL Server Books Online.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Here’s the list of steps you would have to perform moving the data to/from the partitioned table:</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<OL>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Determine the filegroup where the partition with the oldest data resides (this is partition 1 for a LEFT RANGE partition or partition 2 for a RIGHT RANGE partition).</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">If this filegroup is marked as READ_ONLY, change it to READ_WRITE.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">On this filegroup create a non-partitioned archive table, which is an exact copy of the partitioned table.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">If the partitioned table is clustered, create the same clustered index on the archive table.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Using the ALTER TABLE…SWITCH command, switch the partition identified in step 1 into the archive table created in step 3.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Using the ALTER PARTITION FUNCTION command, merge the partition with the lowest partition boundary value, thus dropping the partition switched out in step 5.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">If not done yet, for the partition scheme mark the filegroup, where the staging table resides, as NEXT USED using the ALTER PARTITION SCHEME command. (<SPAN class=GramE>Note, that</SPAN> all partition schemes based on the same partition function need to have a NEXT USED filegroup.)</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">If the filegroup assigned to the last partition of a RIGHT range partition is marked as READ_ONLY, change it to READ_WRITE.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Add a new partition using the ALTER PARTITION FUNCTION…SPLIT command with the new boundary value.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">If CHECK constraints exist on the partitioned <SPAN class=GramE>table that restrict</SPAN> the possible values of the partitioning column, adjust them accordingly (actually, only the upper bounds need to be adjusted).</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Determine the partition number of the new partition added in step 9 (this is the last partition for a RIGHT RANGE partition, or its predecessor for a LEFT RANGE partition).</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Switch the staging table into the partition identified in step 11 using the ALTER TABLE…SWITCH command.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now you can drop the staging table and you might seal the filegroup by designating it as READ_ONLY.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Create a new staging table for the upcoming month, possibly in the filegroup identified in step 1.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Update statistics on the partitioned table.</SPAN></DIV></LI>
<LI>
<DIV class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US">Save and drop the archive table created in step 3 (this step does not have to be performed immediately and can be deferred to a later point in time).<o:p></o:p></SPAN></DIV></LI></OL>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Although this might sound complex, most of it can be scripted. And best of it, these steps (except the last two) can be executed within seconds as no data really are moved and only metadata have to be changed. See <A href="https://sqlpartitionmgmt.codeplex.com/">https://sqlpartitionmgmt.codeplex.com</A> for a program that might be helpful for performing these steps.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt; mso-ansi-language: EN-US">Enhancements in SQL Server 2008 with Regard to Table and Index Partitioning</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">SQL Server 2008 provides several enhancements that affect partitioned tables and indexes. Here I’ll discuss some of those enhanced features. See also&nbsp;<A href="https://technet.microsoft.com/magazine/2008.04.dwperformance.aspx">https://technet.microsoft.com/magazine/2008.04.dwperformance.aspx</A>.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Enhanced parallel query execution<o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In SQL Server 2005, if a query covers more than one partition, only a single thread is being used for executing the query on each partition in parallel. This limits the parallelism of a query in case the number of partitions touched by the query is less than the number of processors available to SQL Server. SQL Server 2008 removes this restriction and distributes the available threads for query processing evenly on all partitions participating in the query.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">For a detailed discussion of this topic see “Parallel Query Execution Strategy for Partitioned Objects” under “Query Processing Enhancements on Partitioned Tables and Indexes” in SQL Server 2008 Books Online.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN></B>&nbsp;</P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Partition-aligned indexed views</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">In SQL Server 2005 you are able to create indexed views on a partitioned table. But these indexed views cannot be partitioned. Hence, before switching partitions you would have to drop the indexed views before the switch and recreate them afterwards. This obviously leaves indexed views on partitioned tables useless in case partition switching is a requirement. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Now, SQL Server 2008 allows <SPAN class=GramE>to partition</SPAN> indexed views as well. Principally, you define the indexed view the same way you do it in SQL Server 2005. There are a few restrictions concerning the inclusion of the partitioning column in the view definition (see “Partition Switching When Indexed Views Are Defined” in SQL Server 2008 Books Online). Then, when materializing the view by creating the unique clustered index on the view, simply use the ON clause to specify the partition scheme and partitioning column. The same rules for partition alignment apply as for partitioned indexes.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Data Compression<o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">SQL Server 2008 allows for compressing data on a row or page level. The good news is, that this feature not only can be set on a whole table or index, but for each partition individually. Thereby, you can enable the more costly page level compression on older partitions, that are not altered very often, and leave the actual <SPAN class=GramE>partition, that</SPAN> gets all the new data, uncompressed or row compressed. You can change the compression state of a partition using the ALTER <SPAN class=GramE>TABLE ..</SPAN> REBUILD PARTITION statement.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">For tables with mixed compression settings for different partitions, you should be aware of <A href="https://support.microsoft.com/kb/957810">https://support.microsoft.com/kb/957810</A>.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Lock Escalation</SPAN></B><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">Instead of escalating the existing fine-grain locks on a table to a single table lock in case the lock escalation threshold has been exceeded, SQL Server 2008 allows to escalate the locks on a single partition into a lock on the heap or B-tree level, thus allowing for greater concurrency than a full table lock.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">This feature can be set for each table individually by specifying SET (LOCK_ESCALATION = AUTO) with the ALTER TABLE statement.&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Support for partitioning in SQL Server Management Studio<o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">The support for partitioning, which Management Studio in SQL Server 2005 provides, is pretty sparse. For instance, you can list and delete the partition schemes and functions defined for a database. But that’s it. Management Studio in SQL Server 2008 extends this functionality by providing several Wizards that may help in creating and maintaining partitioned tables. <SPAN class=GramE>Just right-click a table in the Object Explorer and select Storage in the context menu.</SPAN> Depending on whether the table is already partitioned or not, you can activate the Create Partition Wizard or the Manage Partition Wizard. These wizards allow you to graphically design partition functions and schemes, create a staging table, or to manage partition switching in a sliding window scenario. Although the wizards are quite neat, you always should be alert if the solution to a complex problem is just a few mouse clicks away. The solutions chosen by the wizards might not always be the most practical ones, e.g. if you ask the wizard<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>to partition a table, the solution proposed by the wizard, although correct, certainly is not the one you’d apply to a existing huge table coming with a bunch of indexes. You’d better script the solution first for further examination, instead of immediately running it. But the wizards come in handy during the design phase of a database or for becoming acquainted with partitioning.</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="mso-ansi-language: EN-US">Partitioning of tables with FILESTREAM data<o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">SQL Server 2008 incorporates a new storage scheme for large binary data. If you define a column of type <SPAN class=GramE>VARBINARY(</SPAN>MAX) with the FILESTREAM storage attribute, the column data will be stored in the servers file system instead of database storage. The locations within the file system where these data are <SPAN class=GramE>placed,</SPAN> are defined by special FILESTREAM filegroups. Within the CREATE TABLE statement you have to specify in a FILESTREAM_ON clause the filegroup to be used for the FILESTRAEM data in the table. But, if the table is partitioned, also the FILESTREAM storage is going to be partitioned. Therefore, you have to define a separate partition scheme, based on the same partition function and same partitioning column as the table, and mapping each partition to a FILESTREAM filegroup. And this partition scheme has to be used in the FILESTREAM_ON clause instead.&nbsp;</SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">But there is one more requirement for FILESTREAM columns that lessens the usefulness of partitioning tables with FILESTREAM data. A table with FILESTREAM data also needs to have a column with the ROWGUIDCOL property and an UNIQUE or PRIMARY KEY single-column constraint defined on this column. But as you recall, unique partitioned indexes also have to add the partitioning column to their index keys. Hence, the index for this UNIQUE constraint cannot be partitioned. But as you have learned, an index automatically inherits the storage scheme of its base table and this also applies to UNIQUE constraints defined with the table. Thus, in order to make an UNIQUE constraint within a partitioned table a non-partitioned one, you explicitly have to specify a filegroup to store this index on within the CONSTRAINT definition.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US">But the more important catch here <SPAN class=GramE>is,</SPAN> that you cannot switch partitions in or out while there is a non-aligned index defined on the table. And you cannot simply drop the UNIQUE constraint or disable the pertaining index while performing the switch, as long as there are FILESTREAM data in the table.</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US style="mso-ansi-language: EN-US"></SPAN><SPAN lang=EN-US style="mso-ansi-language: EN-US"><o:p>&nbsp;</o:p></SPAN></P>]]></content:encoded>
    </item>
  </channel>
</rss>