Troubleshooting Guide: Error 6343 – Cannot Create Secondary XML Index Without USING XML INDEX Clause
Why This Error Happens
This error occurs when attempting to create a secondary XML index (PATH, VALUE, or PROPERTY type) or a secondary selective XML index without explicitly referencing the primary XML index via the USING XML INDEX clause. SQL Server 2025 requires this clause because secondary indexes are structurally dependent on an existing primary index to resolve node identifiers and path hierarchies. Omitting this clause leaves the engine unable to determine which primary index the secondary index should extend, causing the operation to fail at the T-SQL parsing/validation stage.
Step-by-Step Resolution Guide
Step 1: Verify the Primary XML Index Exists
- Run the following query to confirm a primary XML index is already created on the target column:
SELECT i.name, i.type_desc, i.is_primary_xml
FROM sys.xml_indexes i
JOIN sys.tables t ON i.object_id = t.object_id
WHERE t.name = 'YourTableName';
- If
is_primary_xmlreturns 0 for all rows, no primary index exists and must be created first.
Step 2: Create the Primary XML Index (If Missing)
- Use this syntax to create the required primary index before attempting a secondary one:
CREATE PRIMARY XML INDEX PXML_YourIndex
ON dbo.YourTable (YourXmlColumn);
- Ensure the table has a clustered index on the primary key, as this is a prerequisite for any XML indexing in SQL Server 2025.
Step 3: Correct the Secondary Index Syntax
- Modify your
CREATE XML INDEXstatement to explicitly include theUSING XML INDEXclause referencing the primary index name. - Correct syntax example:
CREATE XML INDEX SXML_YourIndex
ON dbo.YourTable (YourXmlColumn)
USING XML INDEX PXML_YourIndex
FOR PATH;
- Double-check that the primary index name in the clause matches exactly (case-sensitivity may apply depending on collation settings).
Step 4: Rebuild and Validate the Index Chain
- If working with Selective XML Indexes, confirm the
sys.selective_xml_index_pathscatalog view contains the expected path entries before adding secondary promoted paths. - Re-run the full index creation script from primary to secondary in the correct order within a single transaction to avoid orphaned index states.
Alternative or Verification Steps
- Query
sys.indexesandsys.xml_indexesafter execution to confirm both primary and secondary indexes now appear with the correctsecondary_type_desc(PATH, VALUE, or PROPERTY). - If the error persists, drop any partially created secondary index fragments using
DROP INDEXand restart the creation process from Step 2, ensuring no naming conflicts exist insys.objects.