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

Why This Error Happens

This error occurs when SQL Server validates an XML Schema Collection and finds that a complex type declared as a restriction of a base type has loosened the occurrence constraints (minOccurs/maxOccurs) on one of its particles instead of tightening them. XSD specification rules require that a restricted type can only narrow the cardinality of inherited elements, never widen it — for example, changing minOccurs="1" in the base type to minOccurs="0" in the derived type is illegal. This typically happens after a schema migration, an ORM-generated XSD, or a manually edited .xsd file is registered into a CREATE XML SCHEMA COLLECTION or ALTER XML SCHEMA COLLECTION statement in SQL Server 2025.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema Collection and Type

  • Run the following query to locate the schema collection referenced in the error message:
SELECT name, schema_id, xml_collection_id 
FROM sys.xml_schema_collections 
WHERE name = 'YourSchemaCollectionName';
  • Extract the full XSD using xml_schema_namespace() to inspect the exact type referenced in the %s placeholder of Error 6980:
SELECT xml_schema_namespace('dbo','YourSchemaCollectionName');

Step 2: Compare Base and Derived Type Particles

  • Open the exported XSD in Visual Studio, VS Code, or any XML editor that supports XSD validation.
  • Locate the <xs:complexType> definitions involved — one marked with <xs:restriction base="...">.
  • Check every <xs:element> or <xs:sequence> particle for minOccurs and maxOccurs values.
  • Confirm the derived type’s occurrence range is equal to or narrower than the base type (e.g., base minOccurs="0" maxOccurs="unbounded" → derived must be minOccurs="0" or higher, maxOccurs equal or lower).

Step 3: Correct the XSD Definition

  • Edit the derived complex type so its particle occurrence constraints are restrictive, not permissive, relative to the base type.
  • Example fix:
<!-- Before (invalid) -->
<xs:element name="OrderLine" minOccurs="0" maxOccurs="unbounded"/>

<!-- After (valid, matches or narrows base type range) -->
<xs:element name="OrderLine" minOccurs="1" maxOccurs="10"/>
  • Save the corrected .xsd file.

Step 4: Drop and Recreate the XML Schema Collection

  • SQL Server does not allow in-place alteration that changes occurrence constraints on existing types, so drop and recreate the collection:
DROP XML SCHEMA COLLECTION dbo.YourSchemaCollectionName;
GO
CREATE XML SCHEMA COLLECTION dbo.YourSchemaCollectionName AS N'<Insert corrected XSD here>';
GO
  • If the collection is referenced by existing XML-typed columns, you may need to script and temporarily drop those column constraints first, then reapply them after recreation.

Step 5: Redeploy and Rebind Dependent Objects

  • Re-link any typed XML columns, stored procedures, or CLR objects that reference the schema collection.
  • Run sp_refreshsqlmodule on dependent stored procedures/functions to ensure no stale metadata remains:
EXEC sp_refreshsqlmodule 'dbo.YourStoredProcedure';

Alternative or Verification Steps

  • Verify the fix by re-running the original CREATE/ALTER XML SCHEMA COLLECTION statement — it should complete without Error 6980, and you can confirm success via SELECT * FROM sys.xml_schema_collections WHERE name = 'YourSchemaCollectionName';.
  • If editing the XSD directly is not feasible (e.g., third-party schema), use an XML tool like xmllint --schema or the .NET XmlSchemaSet validator offline first to catch restriction violations before attempting to load the schema into SQL Server 2025.