Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1723: Fix Partition Scheme Issues

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server Error 1723 occurs when you attempt to create or modify an index or table and specify a partition scheme, but the operation fails because the index cannot be aligned with the partitioning logic. To fix this, you must ensure that the partitioning column is included in the index key or that you are creating a non-aligned index by specifying a specific filegroup instead of the partition scheme. This error typically arises during the creation of unique indexes or primary keys where the partitioning column is missing from the definition.

What You'll Need

  • SQL Server Management Studio (SSMS) or a compatible T-SQL editor.
  • Sysadmin or db_owner permissions on the target database to modify table structures and indexes.
  • The name of the existing Partition Function and Partition Scheme used by the table.
  • A backup of the database if you are performing these operations in a production environment.

Step-by-Step

  1. Identify the Conflict: Analyze the T-SQL command that triggered the error. Check if you are using a CREATE INDEX or CREATE UNIQUE INDEX statement. Look for the ON [PartitionSchemeName](ColumnName) clause at the end of the statement. If the column specified in the partition scheme is not part of the index key, SQL Server cannot "align" the index, leading to Error 1723.
  2. Verify the Partitioning Column: Run a query against sys.partition_schemes and sys.index_columns to determine which column the table is actually partitioned on. For example, if your table is partitioned by TransactionDate, any aligned index must include TransactionDate as one of its keys.
  3. Option A: Align the Index (Recommended for Performance): If you want the index to be partitioned along with the data, modify your CREATE INDEX statement to include the partitioning column.

    Example: If your table is partitioned on OrderDate but your index is only on CustomerID, change the statement to: CREATE INDEX IX_CustomerID_OrderDate ON Orders (CustomerID, OrderDate) ON MyPartitionScheme(OrderDate);
  4. Option B: Create a Non-Aligned Index: If the index cannot include the partitioning column (for example, if it must be a unique index on a different column), you cannot use the partition scheme. Instead, specify a single filegroup.

    Example: Change ON MyPartitionScheme(OrderDate) to ON [PRIMARY] or another specific filegroup name. This creates a global index that spans all partitions.
  5. Handle Unique Index Constraints: If you are creating a Primary Key or Unique Constraint, remember that SQL Server requires the partitioning column to be part of the unique key if the index is to be aligned. If the business logic forbids adding the partitioning column to the unique key, you must create the index on a single filegroup (non-aligned).
  6. Execute the Modified Command: Run the updated T-SQL script in SSMS. Verify that the index is created successfully by checking the sys.indexes and sys.partitions views to ensure the data_space_id matches your intention (either the scheme ID or the filegroup ID).
  7. Validate Data Distribution: Once the index is created, run a query to ensure the data is distributed across the partitions as expected. Use $PARTITION function in a SELECT statement to verify that the index entries are residing in the correct partition boundaries.

Common Mistakes

One of the most frequent mistakes is assuming that any index created on a partitioned table must also be partitioned. This is not true. While aligned indexes (those on the partition scheme) offer benefits like easier partition switching, non-aligned indexes (those on a filegroup) are perfectly valid and often necessary for unique constraints that do not involve the partitioning key.

Another common error is attempting to add the partitioning column to the end of a unique index without realizing that this changes the uniqueness definition. If you add OrderDate to a unique index on OrderID, the combination of both must be unique, which is different from OrderID being unique on its own. This can lead to logical errors in application data validation.

Users also frequently forget to check if the partition function has enough boundary values to accommodate the data being indexed. If the index creation involves moving data or rebuilding, and the partition function is missing a range for the current data, the operation will fail, though usually with a different error code, it often complicates the debugging process of Error 1723.

Tips

When choosing between an aligned and non-aligned index, consider your maintenance strategy. Aligned indexes are essential if you plan to use SWITCH PARTITION to archive old data. If the index is not aligned, the SWITCH operation will fail because the index would need to be updated across the entire table, defeating the purpose of the metadata-only switch.

For large tables, always perform index creation with the ONLINE = ON option if you have Enterprise Edition. This prevents the table from being locked for the duration of the index build, which can be significant when dealing with partitioned datasets of several terabytes.

Use a naming convention for your indexes to distinguish between aligned and non-aligned ones. For example, prefix aligned indexes with AIX_ and non-aligned indexes with NIX_. This makes it immediately obvious to other DBAs why a specific index is mapped to a filegroup rather than a partition scheme.

Troubleshooting

If you have added the partitioning column to the index and still receive Error 1723, check for the following:

  • Check for Existing Constraints: Ensure there isn't a pre-existing unique constraint on the table that conflicts with the new index. You may need to drop the constraint before recreating it as a partitioned index.
  • Verify Scheme Mapping: Ensure the partition scheme is correctly mapped to the available filegroups. If a filegroup in the scheme is offline or missing, the index creation will fail. Run SELECT * FROM sys.filegroups to verify status.
  • Review Column Data Types: The column used in the index must exactly match the data type of the column used in the partition function. A mismatch (e.g., INT vs BIGINT) can cause alignment failures.
  • Test with a Small Subset: If the error persists, try creating the index on a non-partitioned copy of the table to ensure the syntax is correct, then re-introduce the partitioning scheme to isolate whether the issue is the syntax or the partitioning logic.

Frequently Asked Questions

Why does a unique index require the partitioning column?

SQL Server must be able to guarantee uniqueness within a partition without scanning every other partition in the table. By including the partitioning column in the key, SQL Server knows exactly which partition a value must reside in, allowing it to enforce uniqueness locally and efficiently.

Can I have both aligned and non-aligned indexes on one table?

Yes. A partitioned table can have multiple aligned indexes (on the partition scheme) and multiple non-aligned indexes (on specific filegroups). This is a common architecture for tables that need both partition switching and global unique lookups.

Does creating a non-aligned index slow down performance?

Not necessarily for reads, but it can impact write performance and maintenance. A non-aligned index cannot be switched during partition management, meaning you must rebuild the index or perform more expensive deletions when archiving data.

What is the difference between a partition function and a partition scheme?

The partition function defines the logic (the boundaries and the range) of how data is split. The partition scheme is the mapping that tells SQL Server which physical filegroup each partition created by the function should be stored on.

Can I convert a non-aligned index to an aligned one later?

You cannot "convert" it directly. You must drop the existing index and recreate it using the ON [SchemeName](Column) syntax, ensuring the partitioning column is included in the index key.