How to fix Error 9538 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 9538 – Selective XML Index SINGLETON Option Conflict

Why This Error Happens

This error occurs when you attempt to create a Selective XML Index (SXI) on an XML column where multiple path expressions point to the same underlying XML path, but the SINGLETON option is inconsistently applied across them. SQL Server requires that if one path entry for a given path expression specifies SINGLETON ON (or OFF), every other path entry sharing that identical path expression within the same selective XML index must use the exact same setting. This typically happens due to a copy-paste error in a multi-path CREATE SELECTIVE XML INDEX statement or when a script was migrated from an older schema without validating the SINGLETON clauses for duplicate paths.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Path Definitions

  • Open the CREATE SELECTIVE XML INDEX or ALTER script that triggered Error 9538 in SQL Server Management Studio (SSMS).
  • Locate the specific selective XML index name referenced in the error message (the %.*ls placeholder will show the actual index name in your error log).
  • Manually scan the FOR clause of the statement to find every path expression that repeats, as these are the entries causing the conflict.

Step 2: Audit Existing Path Nodes in System Views

  • Run a query against the system catalog views to see how the paths are currently registered (if the index partially exists or if you are modifying an existing one):
SELECT path_id, path_expression, is_singleton 
FROM sys.xml_index_nodes 
WHERE object_id = OBJECT_ID('YourTableName');
  • Cross-reference the is_singleton column for duplicate path_expression values to confirm the mismatch (e.g., one row shows 1 and a duplicate row shows 0).

Step 3: Correct the SINGLETON Syntax

  • Edit the T-SQL script to ensure uniformity. If a path /Root/Customer/Name appears twice, both instances must explicitly declare SINGLETON ON or SINGLETON OFF—never a mix of the two.
  • Standardize the syntax as follows:
CREATE SELECTIVE XML INDEX SXI_Index ON dbo.YourTable(XmlColumn)
FOR ('/Root/Customer/Name' AS XQUERY 'xs:string' SINGLETON ON, 
     '/Root/Customer/Name' AS XQUERY 'xs:string' SINGLETON ON)
  • Save the script and re-execute it in a test environment first to confirm the CREATE INDEX command processes without throwing Error 9538.

Step 4: Rebuild the Selective XML Index

  • Once the script is corrected, drop the faulty index definition if it was partially created:
DROP SELECTIVE XML INDEX SXI_Index ON dbo.YourTable;
  • Re-run the corrected CREATE SELECTIVE XML INDEX statement to apply the fixed configuration to the production database.

Alternative or Verification Steps

  • Verification: After the index rebuild, run DBCC CHECKDB or query sys.selective_xml_index_paths to ensure the is_singleton flag is consistent (either all 1s or all 0s) for every duplicate path_expression in the new index.
  • Alternative: If standardizing on SINGLETON ON causes application errors due to non-singleton XML nodes, default to SINGLETON OFF for the ambiguous paths, as this is the safer, more permissive setting for XML structures where a node might repeat under the same parent.