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

Troubleshooting Guide: SQL Server Error 2788 – Synonyms Invalid in Schemabound Object or Constraint

Why This Error Happens

Error 2788 occurs because SQL Server does not allow synonyms to be referenced inside schemabound objects (such as views or functions created WITH SCHEMABINDING) or within CHECK/DEFAULT constraint expressions. This restriction exists because synonyms are late-binding aliases that can be altered or dropped independently of the underlying base object, which conflicts with the dependency-tracking guarantees that schemabinding requires. The error typically surfaces after a database migration, a schema refactor, or when a developer unknowingly uses a synonym name instead of the fully qualified base object name during object creation.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Synonym Reference

  • Run sp_helptext 'YourSchemaboundObjectName' in SSMS to review the object’s definition.
  • Search the script for any CREATE SYNONYM targets being referenced instead of the actual base table or view.
  • Check constraint definitions using: SELECT definition FROM sys.check_constraints WHERE parent_object_id = OBJECT_ID('YourTableName');

Step 2: Resolve the Synonym to Its Base Object

  • Query sys.synonyms to find the real target: SELECT name, base_object_name FROM sys.synonyms WHERE name = 'YourSynonymName';
  • Note the fully qualified base_object_name (format: Server.Database.Schema.Object).
  • Replace the synonym reference in your script with the actual three-part or four-part name.

Step 3: Recreate the Schemabound Object or Constraint

  • Drop the existing broken object: DROP VIEW YourSchemaboundView; or DROP FUNCTION YourSchemaboundFunction;
  • Recreate it using WITH SCHEMABINDING but pointing directly to the base table/view, e.g. CREATE VIEW dbo.vw_Example WITH SCHEMABINDING AS SELECT Col1 FROM dbo.BaseTable;
  • If the issue is in a CHECK constraint, drop it with ALTER TABLE YourTable DROP CONSTRAINT CK_YourConstraint; and recreate it referencing the base object/column directly rather than the synonym.

Step 4: Validate Dependent Objects

  • Run sys.sql_expression_dependencies to confirm no other schemabound objects or constraints still reference the synonym.
  • Example: SELECT * FROM sys.sql_expression_dependencies WHERE referenced_entity_name = 'YourSynonymName';
  • Rebuild or recompile any dependent stored procedures/views using sp_refreshsqlmodule to ensure metadata is current.

Step 5: Apply Permissions and Deploy

  • Ensure the executing login has ALTER and REFERENCES permissions on the base object (not just the synonym).
  • Redeploy the corrected script to your SQL Server 2025 instance on Windows Server 2025 via SSMS or your CI/CD pipeline.
  • Confirm no errors are thrown during object creation in the Messages pane.

Alternative or Verification Steps

  • Verify the fix by running SELECT OBJECTPROPERTY(OBJECT_ID('YourSchemaboundObjectName'), 'IsSchemaBound'); — it should return 1 with no errors on creation.
  • If synonyms are required for cross-database abstraction, consider using views without schemabinding, or reference the base object through a three-part name directly in the schemabound definition instead of relying on a synonym layer.