Why This Error Happens
Error 6962 occurs when SQL Server attempts to register or validate an XML Schema Collection (XSD) that contains a restricted element type (such as elements typed as xs:ID, xs:IDREF, or certain complex content types) with a default or fixed attribute value assigned. The SQL Server XML parser strictly enforces W3C XML Schema constraints, and per W3C specification, elements derived from these specific types are prohibited from carrying default or fixed constraints because it creates ambiguous validation states. This typically surfaces when importing third-party XSDs, migrating schema collections from older SQL Server versions (2019/2022) to SQL Server 2025, or when a schema file has been manually edited and corrupted.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Schema Element
- Run the failing
CREATE XML SCHEMA COLLECTIONorALTER XML SCHEMA COLLECTIONstatement and capture the full error text; the%splaceholder will usually resolve to the specific element name (e.g.,elementName). - Open the source
.xsdfile in a text editor or Visual Studio 2022/2025 XML editor and search for that element name usingCtrl+F. - Check if the element’s type attribute is set to
xs:ID,xs:IDREF,xs:IDREFS, or a complex type derived by restriction/extension from one of these.
Step 2: Remove or Relocate the Default/Fixed Constraint
- Delete the
default="value"orfixed="value"attribute directly from the offending<xs:element>or<xs:attribute>tag. - If the constraint logic is required by your application, move the default-value handling into application-layer code (e.g., C#/.NET data layer) rather than the schema definition.
- Save the corrected XSD file to a known path, such as
C:\SQLSchemas\corrected_schema.xsd.
Step 3: Re-import the Corrected Schema Collection
- Open SQL Server Management Studio (SSMS 21) connected to your SQL Server 2025 instance.
- Drop the old faulty collection if it partially exists:
DROP XML SCHEMA COLLECTION dbo.MySchemaCollection; - Import the fixed file using:
CREATE XML SCHEMA COLLECTION dbo.MySchemaCollection AS N'<paste corrected XSD content here>'; - Alternatively, load it via PowerShell using
Invoke-Sqlcmd -InputFile "C:\SQLSchemas\corrected_schema.xsd"if scripting the deployment.
Step 4: Validate Permissions and Compatibility Level
- Confirm the database compatibility level supports the schema features in use:
SELECT compatibility_level FROM sys.databases WHERE name = 'YourDB';(should be 170 or higher for SQL Server 2025 features). - Ensure the executing login has
ALTERpermission on the XML Schema Collection ordb_ddladminrole membership, as insufficient permissions can sometimes mask as malformed registration errors in chained scripts.
Alternative or Verification Steps
- Verify the fix: Query
sys.xml_schema_collectionsto confirm the collection registered successfully, then run a testINSERTagainst a table using that XML column/type to ensure validation passes without Error 6962. - Alternative: If the XSD originates from a vendor and cannot be edited, use an XSLT transformation step to strip
default/fixedattributes programmatically before passing the content to theCREATE XML SCHEMA COLLECTIONcommand.