Troubleshooting Guide: SQL Server Error 2339 – “Either a memberType attribute or a simpleType child must be present”
Why This Error Happens
This error occurs when SQL Server attempts to parse an XML Schema Collection (XSD) that contains a malformed simpleType definition, specifically where a union or list element is missing its required memberType attribute or an inline simpleType child node. This typically happens due to a corrupted or manually edited XSD file, an incomplete schema migration from an older SQL Server version, or third-party tooling that generates non-compliant XML schema collections during deployment. It can also surface when upgrading databases to SQL Server 2025 if legacy schema collections were created against relaxed validation rules in earlier engine versions.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Schema Collection
- Run the following query to locate XML Schema Collections in the affected database:
SELECT name, schema_id, xml_schema_namespace FROM sys.xml_schema_collections;- Cross-reference the
Locationpath returned in the Error 2339 message with the schema collection name to isolate the exact XSD causing the failure. - Export the schema definition using
SELECT xml_schema_namespace(SCHEMA_NAME(schema_id), name) FROM sys.xml_schema_collections WHERE name = 'YourSchemaName';to inspect it externally.
Step 2: Validate and Repair the XSD Structure
- Open the exported XSD in a validation tool such as Visual Studio 2025 XML Editor or an online XSD validator to confirm the exact line/node failing.
- Locate any
<xs:union>or<xs:list>elements and confirm they either include amemberType="..."attribute or a nested<xs:simpleType>child element — one of the two is mandatory per W3C XML Schema spec. - Manually correct the schema by adding the missing attribute, for example:
<xs:union memberType="xs:string xs:int" />. - Save the corrected file as
FixedSchema.xsdin a working directory such asC:\SQLFixes\Schemas\.
Step 3: Re-register the Corrected Schema Collection
- Drop the broken schema collection (if it’s not actively referenced by typed XML columns):
DROP XML SCHEMA COLLECTION YourSchemaName; - Re-create it using the corrected file:
CREATE XML SCHEMA COLLECTION YourSchemaName AS 'C:\SQLFixes\Schemas\FixedSchema.xsd'; - If the schema is in use by existing typed XML columns, use
ALTER XML SCHEMA COLLECTION YourSchemaName ADD 'C:\SQLFixes\Schemas\FixedSchema.xsd';instead to append the corrected definitions without breaking dependencies.
Step 4: Restart the SQL Server Service and Clear Plan Cache
- On Windows Server 2025 / Windows 11, open Services.msc, locate SQL Server (MSSQLSERVER), and restart it to clear any cached invalid schema references.
- Alternatively, run
DBCC FREEPROCCACHE;from SQL Server Management Studio (SSMS) to flush cached execution plans tied to the old schema.
Alternative or Verification Steps
- Verify the fix by re-running the original DDL/DML operation that triggered Error 2339, and confirm no errors appear in the SQL Server Error Log (
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG). - If re-creating the schema collection isn’t feasible due to dependencies, use
sp_help 'YourSchemaName'to identify dependent objects first, then script out and migrate those objects to a new schema collection built from a validated XSD template.