Troubleshooting Guide: SQL Server Error 2766 – User-Defined Data Type Definition Changed
Why This Error Happens
This error occurs when SQL Server detects a mismatch between the cached metadata for a user-defined data type (UDT) and its current definition in the system catalog, typically caused by schema changes made without updating dependent object metadata. It commonly arises after altering a UDT’s base type, precision, or nullability while stored procedures, views, or compiled plans still reference the old structure. Corrupted metadata cache entries or incomplete replication of schema changes across linked servers can also trigger this inconsistency.
Step-by-Step Resolution Guide
Step 1: Identify the Affected Data Type and Dependencies
- Run
sp_help '<UDT_name>'in SQL Server Management Studio (SSMS) to confirm the current definition. - Query
sys.typesandsys.sql_dependenciesto locate all objects (procedures, views, functions) referencing the UDT. - Note the exact name reported in the error message (the
%.*lsplaceholder will show the real type name in your error log).
Step 2: Clear the Procedure Cache and Metadata
- Execute
DBCC FREEPROCCACHE;to clear cached execution plans that may reference the outdated UDT structure. - Run
DBCC FLUSHPROCINDB(<database_id>);to target a specific database if freeing the entire cache is not desirable in production. - Restart the SQL Server service via
services.mscon Windows Server 2025/Windows 11 if the cache issue persists after flushing.
Step 3: Recreate Dependent Objects
- Script out all stored procedures, views, and functions dependent on the UDT using SSMS’s “Generate Scripts” wizard.
- Drop and recreate these objects using
DROP PROCEDURE/CREATE PROCEDURE(or equivalent) so SQL Server rebinds them to the updated UDT definition. - Alternatively, run
sp_refreshsqlmodule '<object_name>'for each dependent object to refresh bindings without a full drop/recreate.
Step 4: Validate System Catalog Integrity
- Run
DBCC CHECKDB('<database_name>') WITH NO_INFOMSGS, ALL_ERRORMSGS;to rule out catalog corruption. - Check Windows Event Viewer (Application log) for related SQL Server Event ID entries indicating I/O or disk-level corruption affecting system tables.
- If corruption is found, restore the affected database from a known-good backup rather than attempting in-place repair.
Alternative or Verification Steps
- After applying fixes, re-run the original query or stored procedure that triggered Error 2766 to confirm it executes without the metadata warning.
- If the error persists, drop and fully recreate the user-defined data type itself (
DROP TYPE/CREATE TYPE), then reapply it to all dependent columns and objects to force a clean metadata rebind.