Troubleshooting Guide: SQL Server Error 10129 – View Creation Failure on Table-Valued Functions
Why This Error Happens
This error occurs because SQL Server does not permit the creation of indexed views (or views with schemabinding requiring certain metadata operations) that reference inline or multi-statement table-valued functions (TVFs). The SQL Server query optimizer cannot resolve the underlying base table dependencies and column-level schema binding through a TVF layer, as it can with direct table or standard view references. This limitation is by design in the SQL Server relational engine and is not caused by corruption, permissions, or configuration drift—it is a structural restriction in how views are bound to function calls.
Step-by-Step Resolution Guide
Step 1: Identify the Offending View and Function
- Open SQL Server Management Studio (SSMS) and locate the view mentioned in the error message (the
%.*lsplaceholder for the view name). - Run
sp_helptext 'YourViewName'to retrieve the full view definition. - Note the specific table-valued function referenced (the second
%.*lsplaceholder) and runsp_helptext 'YourFunctionName'to review its logic.
Step 2: Manually Expand the Function Logic into the View
- Copy the
SELECTstatement and anyJOIN,WHERE, orCASElogic from inside the TVF definition. - Paste this logic directly into the view’s
CREATE VIEWorALTER VIEWscript, replacing the call to the function (e.g.,SELECT * FROM dbo.MyFunction(@param)). - Ensure you manually substitute any function parameters with literal values, variables, or correlated subquery logic that matches the original intent of the function.
- Example transformation:
- Before:
SELECT a.ID FROM dbo.Orders a CROSS APPLY dbo.GetOrderDetails(a.ID) b - After:
SELECT a.ID FROM dbo.Orders a INNER JOIN dbo.OrderDetails b ON a.ID = b.OrderID
Step 3: Apply Schema Binding (If Required)
- If the view requires
WITH SCHEMABINDING(common for indexed views), ensure every table referenced in your newly expanded code uses two-part naming (e.g.,dbo.TableName). - Remove any remaining calls to user-defined functions (UDFs) within the view body, as schema-bound views cannot reference non-deterministic or complex TVFs.
- Re-run the
ALTER VIEWscript in SSMS to validate the syntax.
Step 4: Rebuild Indexes and Validate Dependencies
- If this view is intended to be an indexed view, recreate the unique clustered index using:
CREATE UNIQUE CLUSTERED INDEX IX_ViewName ON dbo.YourViewName (Column1). - Check
sys.sql_expression_dependenciesto confirm the view no longer lists the old TVF as a dependency.
Alternative or Verification Steps
- Verification: Query
sys.viewsandsys.objectsto confirm the view compiles without theWITH SCHEMABINDINGerror, and attempt toSELECT TOP 10 * FROM YourViewNameto ensure data returns correctly. - Alternative: If the function logic is too complex to “flatten” manually, consider converting the business logic into a standard Stored Procedure instead of a view, as stored procedures do not have the same schema-binding restrictions regarding TVFs.