The column "%.*ls" cannot be modified because it is either a computed column or is the result of a UNION operator

Error Message:
Msg 271, Level 16, State 1, Line 13
The column “%.*ls” cannot be modified because it is either a computed column or is the result of a UNION operator.

Severity level:
16.

Description:
This error message appears when during an UPDATE operation either the value for a computed column in a base table should be modified or this column the result of a statement is, that uses the UNION operator.

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. You must modify the UPDATE statement to not try to modifiy the computed column. Resp. the UNION statement must be modified.

Versions:
All versions of SQL Server

Example(s):
CREATE TABLE #t
(
 c1 INT
 , c2 INT
 , c3 AS c1 * c2
)

INSERT INTO #t SELECT 1, 2
UNION ALL SELECT 2, 4
SELECT *
  FROM #t

UPDATE #t
   SET c3 = 1
 WHERE c1 = 1
 
DROP TABLE #t

Remarks:
The above example tries to update the value of a computed column. Because this is an illegal operation, the error is raised.

]]>

Leave a comment

Your email address will not be published.