Troubleshooting Guide: Error 12842 – “The COLLATE CATALOG_DEFAULT clause cannot be used in a constraint”
Why This Error Happens
This error occurs because COLLATE CATALOG_DEFAULT is a dynamic collation reference that resolves its value based on the database catalog at the time of query execution, but constraints (such as CHECK, DEFAULT, or computed column constraints) require a static, deterministic collation to be evaluated and stored at creation time. SQL Server 2025 enforces stricter validation during constraint binding, rejecting any collation clause that cannot be resolved to a fixed value during the CREATE TABLE or ALTER TABLE operation. This typically surfaces when scripts migrated from contained databases (which rely heavily on CATALOG_DEFAULT) are deployed against a non-contained or differently configured database.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Constraint Definition
- Open the T-SQL script or stored procedure that triggered Error 12842.
- Search for any
CHECK,DEFAULT, or computed column definitions containingCOLLATE CATALOG_DEFAULT. - Run the following query in SSMS to locate the table/column if the error occurred during deployment:
SELECT object_name(object_id), definition FROM sys.check_constraints WHERE definition LIKE '%CATALOG_DEFAULT%';
Step 2: Replace CATALOG_DEFAULT with an Explicit Collation
- Determine the actual collation your database is using by running:
SELECT DATABASEPROPERTYEX('YourDatabaseName', 'Collation');
- Edit the constraint definition to replace
COLLATE CATALOG_DEFAULTwith the explicit collation name returned above (e.g.,COLLATE SQL_Latin1_General_CP1_CI_AS). - Drop and recreate the constraint using
ALTER TABLE YourTable DROP CONSTRAINT ConstraintName;followed by the correctedADD CONSTRAINTstatement.
Step 3: Verify Database Containment Settings
- Check whether the database was intended to be a Contained Database, since
CATALOG_DEFAULTis only valid in that context for certain operations. - In SSMS, right-click the database → Properties → Options → verify the Containment Type field.
- If containment was accidentally set to
NONEon Windows Server 2025, either enable partial containment via:
ALTER DATABASE YourDatabaseName SET CONTAINMENT = PARTIAL;
or permanently remove the CATALOG_DEFAULT reference if containment is not required.
Step 4: Redeploy the Schema Change
- Re-run the corrected
CREATE TABLEorALTER TABLEscript. - Confirm no other dependent objects (views, triggers) still reference the old constraint logic with
CATALOG_DEFAULT.
Alternative or Verification Steps
- Verify the fix by querying
sys.check_constraintsorsys.default_constraintsagain to confirm thedefinitioncolumn no longer containsCATALOG_DEFAULTand instead shows a static collation name. - If the error persists, as an alternative, move the collation logic out of the constraint entirely and enforce it at the application layer or via a scalar function with a hardcoded
COLLATEclause instead of relying on catalog-level defaults.