Cannot schema bind %S_MSG ‘%.*ls’ because name ‘%.*ls’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

Error Message:
Msg 4512, Level 16, State 3, Procedure MyOrderView, Line 4
Cannot schema bind %S_MSG ‘%.*ls’ because name ‘%.*ls’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

Severity level:
16.

Description:
This error message appears when you try to create a indexed view that contains a more than two parts column reference.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Errors of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. A column reference can only be two-parted at most.

Versions:
All versions of SQL Server.

Example(s):
USE tempdb;
GO
SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING,
    ANSI_WARNINGS,
    CONCAT_NULL_YIELDS_NULL,
    ARITHABORT,
    QUOTED_IDENTIFIER,
    ANSI_NULLS ON;
GO

IF OBJECT_ID (‘dbo.MyOrderView’, ‘View’) > 0
   DROP VIEW dbo.MyOrderView;
GO
CREATE VIEW dbo.MyOrderView
WITH SCHEMABINDING
AS
SELECT TOP 100 od.UnitPrice*od.Quantity AS Revenue,
    o.OrderDate, od.ProductID
  FROM Northwind.dbo.[Order Details] AS od
  JOIN Northwind.dbo.Orders AS o
    ON od.OrderID = o.OrderID
 ORDER BY o.OrderDate
GO

CREATE UNIQUE CLUSTERED INDEX cix_MyOrderView
    ON dbo.MyOrderView (OrderDate, ProductID);
GO

Remarks:
In the above example we try to use the three part object reference Northwind.dbo.Orders and Northwind.dbo.[Order Details]. This raises the error.




Related Articles :

  • No Related Articles Found

One Response to “Cannot schema bind %S_MSG ‘%.*ls’ because name ‘%.*ls’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.”

  1. Why doesn’t this work as a view:

    SELECT
    requirementId,
    requirementName = replace(TP_Policy.dbo.urlDecode(requirementName),’+',’ ‘),
    requirementLabel,
    active
    FROM mydb..requirements

    If I remove the three part reference the error message says the function is not recognizable.

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |