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

Troubleshooting Guide: SQL Server Error 1956 – Nondeterministic Function in Indexed View

Why This Error Happens

This error occurs because SQL Server requires all functions referenced in an indexed (materialized) view to be deterministic—meaning they must always return the same result for the same input values. When a user-defined function (UDF) relies on non-deterministic operations (such as GETDATE(), RAND(), or external system calls), the Query Optimizer cannot guarantee consistent index results, so it blocks the index creation. This typically happens when developers migrate standard views to indexed views without auditing the underlying function logic for volatility.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Function

  • Open SQL Server Management Studio (SSMS) and locate the specific view mentioned in the error message (%.*ls).
  • Run sp_helptext 'YourViewName' to view the underlying SQL definition and find which UDF is being called.
  • Check the function’s definition using OBJECTPROPERTY(OBJECT_ID('YourFunctionName'), 'IsDeterministic'). A return value of 0 confirms it is nondeterministic.

Step 2: Refactor the Function Logic

  • Remove any calls to nondeterministic system functions (e.g., NEWID(), RAND(), GETDATE(), CURRENT_TIMESTAMP) from within the UDF.
  • If the logic requires a timestamp, consider moving that calculation outside the view and passing it in as a parameter instead, or restructure the UDF to rely solely on SCHEMABINDING and deterministic math/string operations.
  • Ensure the function is created WITH SCHEMABINDING, as this is a prerequisite for determinism recognition in SQL Server 2025.

Step 3: Modify the View Definition

  • If refactoring the function is not feasible, remove the direct reference to the UDF from the SELECT statement of the view.
  • Replace the function call with the raw calculation or logic directly inside the view’s SELECT clause (in-lining the logic).
  • Re-run the CREATE UNIQUE CLUSTERED INDEX statement on the view to test if the schema binding now accepts the deterministic logic.

Step 4: Verify Schema Binding Integrity

  • Navigate to Object Explorer > Databases > [Your DB] > Views in SSMS.
  • Right-click the view and select Properties to ensure “Schema Bound” is set to True.
  • Confirm there are no SELECT * statements in the view, as this breaks determinism checks in Windows Server 2025 environments.

Alternative or Verification Steps

  • Verification: Attempt to re-run the CREATE INDEX command. If successful, run DBCC CHECKTABLE on the indexed view to ensure data integrity across the Windows Server 2025 cluster.
  • Alternative: If the function absolutely must remain nondeterministic (e.g., for CLR integration), abandon the indexed view approach and use a standard view combined with a nightly SQL Server Agent Job to populate a physical “snapshot” table instead.