persisted, computed column
Posted on 2013-01-16
Simple table with two ID's that come from two other tables. IF SecondID is NULL, I want it to DEFAULT to the FirstID. At first I thought I would do an AFTER INSERT trigger, but I really do try to avoid triggers, whenever I can.
So, I thought I'd try the computed column, persisted.
CREATE TABLE [dbo].[table](
[uniqueID] [int] IDENTITY(1,1) NOT NULL,
[FirstID] [int] NOT NULL,
[SecondID] AS (CASE
WHEN [SecondID] IS NULL THEN [FirstID] ELSE [SecondID] END) PERSISTED,
Msg 402, Level 16, State 1, Line 7
The data types void type and void type are incompatible in the is operator.
Msg 1911, Level 16, State 1, Line 2
Column name 'SecondID' does not exist in the target table or view.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Please let me know, if you can.