I have different versions of SQL Server databases:
- in
DB 1
, column 'IsReadOnly' is a computed column - in
DB 2
, column 'IsReadOnly' is a NON computed column
I need to create a standard script which will work on both versions:
IF EXISTS (SELECT 1 FROM sys.columns
WHERE Name = N'IsReadOnly'
AND Object_ID = OBJECT_ID(N'dbo.TableA')
AND is_computed = 0)
BEGIN
UPDATE TableA
SET IsReadOnly = @IsReadOnly
WHERE Id = @ID
END
When running the above, it works on the version where is_computed = 0. But when running on the version where is_computed = 1 I get:
Msg 271, Level 16, State 1, Line 322
The column "IsReadOnly" cannot be modified because it is either a computed column or is the result of a UNION operator
Any help very much appreciated. Thanks