SQL Server Error 1722 Partition Scheme Fix Guide
In this article
SQL Server Error 1722 occurs when you attempt to create or modify an index or table that requires a partition scheme, but the specified scheme does not exist or is inaccessible. To resolve this, you must either create the missing partition scheme and its associated partition function, or correct the syntax in your T-SQL script to reference a scheme that already exists in the database. This error typically surfaces during the restoration of a database, the movement of data files, or when deploying scripts across different environments where the partitioning infrastructure was not mirrored.
What You'll Need
- SQL Server Management Studio (SSMS) or a similar T-SQL editor.
- Sysadmin or db_owner permissions on the target database to create partition functions and schemes.
- Knowledge of the intended partitioning logic (the boundary values and the filegroups where data should reside).
- Access to the database's filegroup configuration to ensure the destination files exist.
Step-by-Step
- Identify the Missing Scheme: Examine the full text of Error 1722. The error message usually specifies the name of the partition scheme that SQL Server cannot find. Note this name exactly, as SQL Server identifiers are case-sensitive if the database collation is case-sensitive.
- Verify Existing Schemes: Run a query against the system catalog to see if the scheme exists under a different name or if it is truly missing. Use the following query:
SELECT name FROM sys.partition_schemes;
If the name from the error message does not appear in this list, you have confirmed the scheme is missing. - Create the Partition Function: A partition scheme cannot exist without a partition function. The function defines how the data is split (the boundaries). Determine if you need a RANGE LEFT (boundary value is the upper limit of the partition) or RANGE RIGHT (boundary value is the lower limit).
Example:CREATE PARTITION FUNCTION pfSalesDate (datetime) AS RANGE RIGHT FOR VALUES ('2023-01-01', '2024-01-01'); - Define the Filegroups: Before creating the scheme, ensure the filegroups you intend to use are already created in the database. If you want all partitions on the PRIMARY filegroup, you only need one. If you are spreading data across multiple disks for performance, create those filegroups via the Database Properties > Filegroups menu in SSMS.
- Create the Partition Scheme: Now, map the partition function to the filegroups. The number of filegroups listed must be exactly one more than the number of boundary values in your function.
Example:CREATE PARTITION SCHEME psSalesDate AS PARTITION pfSalesDate TO ([PRIMARY], [PRIMARY], [PRIMARY]);
If you want all subsequent partitions to go to a specific filegroup, you can use the "ALL TO" syntax:CREATE PARTITION SCHEME psSalesDate AS PARTITION pfSalesDate ALL TO ([PRIMARY]); - Re-run the Failed Command: Once the scheme is created, execute the original T-SQL statement that triggered Error 1722 (such as the
CREATE INDEXorCREATE TABLEstatement). The engine will now find the scheme and successfully allocate the data. - Validate the Partitioning: To ensure the table or index is now correctly partitioned, query the
sys.partitionsview to confirm that the data is distributed across the expected partition numbers.
Common Mistakes
One of the most frequent mistakes is attempting to create the partition scheme before the partition function. In SQL Server, the function is the logic and the scheme is the physical mapping; the logic must exist first. Another common error is a mismatch between the number of filegroups provided in the scheme definition and the number of boundaries defined in the function. If your function has four boundary values, your scheme must map to five filegroups (or use the "ALL TO" shortcut).
Users also frequently overlook collation settings. If a database is migrated from a case-insensitive server to a case-sensitive server, a scheme named "PS_Sales" will not be recognized if the script calls for "ps_sales". Additionally, some administrators attempt to create a partition scheme in the master database instead of the specific user database where the table resides, leading to the same 1722 error because the scheme is not visible to the user database.
Tips
When deploying scripts to multiple environments (Dev, Test, Prod), always include a check for the existence of the partition scheme at the top of your script. Using an IF NOT EXISTS block prevents the script from failing if the scheme is already there, while ensuring it is created if it is missing. This makes your deployment idempotent and reduces the likelihood of Error 1722 during automated CI/CD pipelines.
For those managing very large datasets, consider using a single filegroup for all partitions initially. While spreading partitions across multiple physical disks can improve I/O, it increases administrative complexity. You can always move partitions to different filegroups later using the ALTER PARTITION SCHEME command and rebuilding the indexes. This simplifies the initial setup and avoids errors related to missing filegroups during the creation of the scheme.
Troubleshooting
If you have created the partition scheme and the partition function, but you are still receiving Error 1722, check the following in order:
First, verify that you are connected to the correct database. It is common to accidentally run a script against the master database when the target table is in a user database. Use the USE [DatabaseName]; command at the start of your script to be certain.
Second, check for orphaned partition functions. Sometimes a scheme is deleted but the function remains. If you try to recreate the scheme using an existing function that has a different data type than the table column you are partitioning, the operation will fail. Drop both the scheme and the function and recreate them from scratch to ensure the data types match perfectly.
Third, if this error occurs during a database restore or a dbcc checkdb operation, it may indicate corruption in the system catalogs. In this rare case, check the SQL Server Error Log for any "consistency error" messages. If corruption is present, you may need to restore from a known good backup or perform a repair operation, though this should be a last resort.
Frequently Asked Questions
Can I change the partition scheme after a table is created?
You cannot simply rename or swap a partition scheme for an existing table. To change the scheme, you typically need to create a new scheme and then rebuild the clustered index on the table using the new scheme, which effectively moves the data.
What is the difference between a partition function and a partition scheme?
The partition function defines the boundary values (the "where") that determine which row goes into which partition. The partition scheme maps those partitions to physical storage locations or filegroups (the "how").
Does Error 1722 happen with non-partitioned tables?
No. This error specifically relates to partitioning. If you see this error on a table you didn't intend to partition, check if you are using a template or a script that includes a ON [SchemeName](Column)` clause at the end of the CREATE TABLE statement.
Why does my script fail even though the scheme exists in SSMS?
This is usually due to a permissions issue or a database context error. Ensure the user executing the script has the ALTER permission on the schema and that the script is explicitly targeting the database where the scheme was created.
Can I use a partition scheme across multiple databases?
No, partition schemes and functions are database-scoped objects. They must be created individually within every database that requires them.