Create the 3rd column that is calculated
CREATE TABLE MyTable ( COLUMN_PK int NOT NULL identity(1,1) , ... COLUMN_NUM_internal int NULL, COLUMN_NUM AS COALESCE (COLUMN_NUM_internal, COLUMN_PK), ... )
The PK value is unknown before INSERT (of course). But not before, so you do something like this or use a trigger to update COLUMN_NUM. However, this solution above works for subsequent UPDATEs also without additional code (i.e., another trigger for UPDATE)
source share