View or function '%.*ls' is not updatable because the modification affects multiple base tables.

Error Message:
Msg 4405, Level 16, State 1, Line 1
View or function ‘%.*ls’ is not updatable because the modification affects multiple base tables.

Severity level:
16.

Description:
This error message appears when you try to update data in a view that affects more than one base table.

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. You cannot use a view to update data in more than one base table at a time. Consider using a stored procedure instead.

Versions:
All versions of SQL Server.

Example(s):
USE Northwind;
GO
IF OBJECT_ID(‘dbo.MyOrders’, ‘View’) > 0
 DROP VIEW dbo.MyOrders
GO
CREATE VIEW dbo.MyOrders
AS
SELECT od.Discount, o.ShippedDate
  FROM dbo.Orders o
  JOIN [Order Details] od
    ON o.OrderID = od.OrderID
GO
UPDATE dbo.MyOrders
   SET ShippedDate = NULL, Discount = NULL
 WHERE ShippedDate IS NULL

Remarks:
In the above example we try to update the view dbo.MyOrders. Because the SELECT list of the view contains columns from more than one base table, the error is raised.

]]>

Leave a Reply

Your email address will not be published. Required fields are marked *