Cannot schema bind %S_MSG '%.*ls' because it references system object '%.*ls'.

Error Message:
Msg 2720, Level 16, State 1, Procedure MyOrderView, Line 4
Cannot schema bind %S_MSG ‘%.*ls’ because it references system object ‘%.*ls’.

Severity level:
16.

Description:
This error message appears when you try to bind a view, that accesses system objects to a schema.

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

Resolution:
Error 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. System objects cannot be referenced in views that you want to bind to a schema.

Versions:
All versions of SQL Server

Example(s):
USE Northwind;
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 od.OrderID, od.UnitPrice*od.Quantity AS Revenue,
    o.OrderDate, od.ProductID
  FROM dbo.[Order Details] AS od
  JOIN dbo.Orders AS o
    ON od.OrderID = o.OrderID
    CROSS JOIN sys.columns
GO

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

Remarks:
In the above example we try to bind a view to a schema, that accesses the sys.columns system table. This raises the error.

]]>

Leave a comment

Your email address will not be published.