{"id":3240,"date":"2022-04-13T13:23:26","date_gmt":"2022-04-13T06:23:26","guid":{"rendered":"https:\/\/www.sqlservertutorial.net\/?page_id=3240"},"modified":"2022-04-13T13:23:28","modified_gmt":"2022-04-13T06:23:28","slug":"sql-server-partition-existing-table","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/","title":{"rendered":"SQL Server Partition Existing Table"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to partition an existing table in SQL Server using T-SQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='partitioning-an-existing-table-using-t-sql'>Partitioning an existing table using T-SQL <a href=\"#partitioning-an-existing-table-using-t-sql\" class=\"anchor\" id=\"partitioning-an-existing-table-using-t-sql\" title=\"Anchor for Partitioning an existing table using T-SQL\">#<\/a><\/h2>\n\n\n\n<p>The steps for <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-table-partitioning\/\">partitioning<\/a> an existing table are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create filegroups<\/li><li>Create a partition function<\/li><li>Create a partition scheme<\/li><li>Create a clustered index on the table based on the partition scheme.<\/li><\/ul>\n\n\n\n<p>We&#8217;ll partition the <code>sales.orders<\/code> table in the <code>BikeStores<\/code> database by years.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='create-filegroups'>Create filegroups <a href=\"#create-filegroups\" class=\"anchor\" id=\"create-filegroups\" title=\"Anchor for Create filegroups\">#<\/a><\/h3>\n\n\n\n<p>First, create two new file groups will store the rows with the order dates in 2016 and 2017:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> bikestores\n<span class=\"hljs-keyword\">ADD<\/span> FILEGROUP salesorders_2016;\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> bikestores\n<span class=\"hljs-keyword\">ADD<\/span> FILEGROUP salesorders_2017;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, map the filegroups with the physical files. Note that you need to have the <code>D:\\data<\/code> folder in the server before executing the following statements:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> bikestores    \n<span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">FILE<\/span>     (\n    <span class=\"hljs-keyword\">NAME<\/span> = salesorders_2016,\n    FILENAME = <span class=\"hljs-string\">'D:\\data\\salesorders_2016.ndf'<\/span>,\n        <span class=\"hljs-keyword\">SIZE<\/span> = <span class=\"hljs-number\">10<\/span> MB, \n        <span class=\"hljs-keyword\">MAXSIZE<\/span> = <span class=\"hljs-keyword\">UNLIMITED<\/span>, \n        FILEGROWTH = <span class=\"hljs-number\">1024<\/span> KB\n    ) <span class=\"hljs-keyword\">TO<\/span> FILEGROUP salesorders_2016;\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> bikestores    \n<span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">FILE<\/span>     (\n    <span class=\"hljs-keyword\">NAME<\/span> = salesorders_2017,\n    FILENAME = <span class=\"hljs-string\">'D:\\data\\salesorders_2017.ndf'<\/span>,\n        <span class=\"hljs-keyword\">SIZE<\/span> = <span class=\"hljs-number\">10<\/span> MB, \n        <span class=\"hljs-keyword\">MAXSIZE<\/span> = <span class=\"hljs-keyword\">UNLIMITED<\/span>, \n        FILEGROWTH = <span class=\"hljs-number\">1024<\/span> KB\n    ) <span class=\"hljs-keyword\">TO<\/span> FILEGROUP salesorders_2017;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='create-a-partition-function'>Create a partition function <a href=\"#create-a-partition-function\" class=\"anchor\" id=\"create-a-partition-function\" title=\"Anchor for Create a partition function\">#<\/a><\/h3>\n\n\n\n<p>Create a partition function that accepts a date and returns three partitions:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> sales_order_by_year_function(<span class=\"hljs-built_in\">date<\/span>)\n<span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">RANGE<\/span> <span class=\"hljs-keyword\">LEFT<\/span> \n<span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-string\">'2016-12-31'<\/span>, <span class=\"hljs-string\">'2017-12-31'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='create-a-partition-scheme'>Create a partition scheme <a href=\"#create-a-partition-scheme\" class=\"anchor\" id=\"create-a-partition-scheme\" title=\"Anchor for Create a partition scheme\">#<\/a><\/h3>\n\n\n\n<p>Create a partition scheme based on the <code>sales_order_by_year_function<\/code> partition function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PARTITION<\/span> SCHEME sales_order_by_year_scheme\n<span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">PARTITION<\/span> sales_order_by_year_function\n<span class=\"hljs-keyword\">TO<\/span> (&#91;salesorders_2016], &#91;salesorders_2017], &#91;primary]);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='create-a-clustered-index-on-the-partitioning-column'>Create a clustered index on the partitioning column <a href=\"#create-a-clustered-index-on-the-partitioning-column\" class=\"anchor\" id=\"create-a-clustered-index-on-the-partitioning-column\" title=\"Anchor for Create a clustered index on the partitioning column\">#<\/a><\/h3>\n\n\n\n<p>The <code>orders<\/code> table has the <code>order_id<\/code> as the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-primary-key\/\">primary key<\/a>. This primary key column is also included in a <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-indexes\/sql-server-clustered-indexes\/\">clustered index<\/a>. <\/p>\n\n\n\n<p>To partition the <code>orders<\/code> table by the <code>order_date<\/code> column, you need to create a clustered index for the <code>order_date<\/code> column on the partition scheme <code>sales_order_by_year_scheme<\/code>.<\/p>\n\n\n\n<p>To do that, you need to change the clustered index that includes the <code>order_id<\/code> column to a non-clustered index so that you can create a new clustered index that includes the <code>order_date<\/code> column.<\/p>\n\n\n\n<p>But the <code>order_id<\/code> is referenced by a <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-foreign-key\/\">foreign key<\/a> in the <code>order_items<\/code> table. Therefore, you need to perform these steps:<\/p>\n\n\n\n<p>First, remove the foreign key <code>order_id<\/code> from the <code>order_items<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;order_items] \n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">CONSTRAINT<\/span> &#91;FK__order_ite__order__3A81B327]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that the constraint name <code>FK__order_ite__order__3A81B327<\/code> may be different in your database.<\/p>\n\n\n\n<p>Second, remove the primary key constraint from the <code>orders<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;orders] \n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">CONSTRAINT<\/span> &#91;PK__orders__46596229EDE70106];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, add the <code>order_id<\/code> as a non-clustered primary key on the <code>PRIMARY<\/code> partition:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;orders] \n<span class=\"hljs-keyword\">ADD<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span> NONCLUSTERED(&#91;order_id] <span class=\"hljs-keyword\">ASC<\/span>) \n<span class=\"hljs-keyword\">ON<\/span> &#91;PRIMARY];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, create a clustered index that includes the <code>order_date<\/code> column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> CLUSTERED <span class=\"hljs-keyword\">INDEX<\/span> ix_order_date \n<span class=\"hljs-keyword\">ON<\/span> &#91;sales].&#91;orders]\n(\n\t&#91;order_date]\n) <span class=\"hljs-keyword\">ON<\/span> &#91;sales_order_by_year_scheme](&#91;order_date])<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fifth, drop the clustered index:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">INDEX<\/span> ix_order_date \n<span class=\"hljs-keyword\">ON<\/span> &#91;sales].&#91;orders];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, add the foreign key constraint back to the <code>order_items<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;order_items]  \n<span class=\"hljs-keyword\">WITH<\/span> <span class=\"hljs-keyword\">CHECK<\/span> <span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span>(&#91;order_id])\n<span class=\"hljs-keyword\">REFERENCES<\/span> &#91;sales].&#91;orders] (&#91;order_id])\n<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It&#8217;s better to run all the statements above in a <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-transaction\/\">transaction<\/a> like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">BEGIN<\/span> <span class=\"hljs-keyword\">TRANSACTION<\/span>;\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;order_items] \n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">CONSTRAINT<\/span> &#91;FK__order_ite__order__3A81B327];\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;orders] \n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">CONSTRAINT<\/span> &#91;PK__orders__46596229EDE70106];\n\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;orders] <span class=\"hljs-keyword\">ADD<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span> NONCLUSTERED \n(\n\t&#91;order_id] <span class=\"hljs-keyword\">ASC<\/span>\n) <span class=\"hljs-keyword\">ON<\/span> &#91;PRIMARY];\n\n<span class=\"hljs-keyword\">CREATE<\/span> CLUSTERED <span class=\"hljs-keyword\">INDEX<\/span> ix_order_date \n <span class=\"hljs-keyword\">ON<\/span> &#91;sales].&#91;orders]\n(\n\t&#91;order_date]\n) <span class=\"hljs-keyword\">ON<\/span> &#91;sales_order_by_year_scheme](&#91;order_date]);\n\n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">INDEX<\/span> ix_order_date \n<span class=\"hljs-keyword\">ON<\/span> &#91;sales].&#91;orders];\n\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> &#91;sales].&#91;order_items]  \n<span class=\"hljs-keyword\">WITH<\/span> <span class=\"hljs-keyword\">CHECK<\/span> <span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span>(&#91;order_id])\n<span class=\"hljs-keyword\">REFERENCES<\/span> &#91;sales].&#91;orders] (&#91;order_id])\n<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>;\n\n<span class=\"hljs-keyword\">COMMIT<\/span> <span class=\"hljs-keyword\">TRANSACTION<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To check the number of rows in each partition, you use the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n\tp.partition_number <span class=\"hljs-keyword\">AS<\/span> partition_number,\n\tf.name <span class=\"hljs-keyword\">AS<\/span> file_group, \n\tp.rows <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">row_count<\/span>\n<span class=\"hljs-keyword\">FROM<\/span> sys.partitions p\n<span class=\"hljs-keyword\">JOIN<\/span> sys.destination_data_spaces dds <span class=\"hljs-keyword\">ON<\/span> p.partition_number = dds.destination_id\n<span class=\"hljs-keyword\">JOIN<\/span> sys.filegroups f <span class=\"hljs-keyword\">ON<\/span> dds.data_space_id = f.data_space_id\n<span class=\"hljs-keyword\">WHERE<\/span> OBJECT_NAME(OBJECT_ID) = <span class=\"hljs-string\">'orders'<\/span>\n<span class=\"hljs-keyword\">order<\/span> <span class=\"hljs-keyword\">by<\/span> partition_number;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Create a clustered index on a partitioning column based on a partition scheme to partition an existing table.<\/li><\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3240\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/\"\n\t\t\t\tdata-post-title=\"SQL Server Partition Existing Table\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3240\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/\"\n\t\t\t\tdata-post-title=\"SQL Server Partition Existing Table\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you&#8217;ll learn how to partition an existing table in SQL Server using T-SQL. Partitioning an existing table using T-SQL # The steps for partitioning an existing table are as follows: Create filegroups Create a partition function Create a partition scheme Create a clustered index on the table based on the partition [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2903,"menu_order":22,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3240","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Server Partition Existing Table<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Partition Existing Table\" \/>\n<meta property=\"og:description\" content=\"Summary: in this tutorial, you&#8217;ll learn how to partition an existing table in SQL Server using T-SQL. Partitioning an existing table using T-SQL # The steps for partitioning an existing table are as follows: Create filegroups Create a partition function Create a partition scheme Create a clustered index on the table based on the partition [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T06:23:28+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/sql-server-partition-existing-table\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/sql-server-partition-existing-table\\\/\",\"name\":\"SQL Server Partition Existing Table\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"datePublished\":\"2022-04-13T06:23:26+00:00\",\"dateModified\":\"2022-04-13T06:23:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/sql-server-partition-existing-table\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/sql-server-partition-existing-table\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/sql-server-partition-existing-table\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Administration\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-administration\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server Partition Existing Table\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server Partition Existing Table","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Partition Existing Table","og_description":"Summary: in this tutorial, you&#8217;ll learn how to partition an existing table in SQL Server using T-SQL. Partitioning an existing table using T-SQL # The steps for partitioning an existing table are as follows: Create filegroups Create a partition function Create a partition scheme Create a clustered index on the table based on the partition [&hellip;]","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2022-04-13T06:23:28+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/","name":"SQL Server Partition Existing Table","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"datePublished":"2022-04-13T06:23:26+00:00","dateModified":"2022-04-13T06:23:28+00:00","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-partition-existing-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Administration","item":"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/"},{"@type":"ListItem","position":3,"name":"SQL Server Partition Existing Table"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=3240"}],"version-history":[{"count":5,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3240\/revisions"}],"predecessor-version":[{"id":3246,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3240\/revisions\/3246"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/2903"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=3240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}