As I wrote in my comment, I would not set the existing value to null
. Instead, a computed column seems like a better option to me.
Also, varchar(1)
is the second worst data type you can choose (nvarchar(1)
is even worst). First, if you know you only ever going to have a fixed length string, use char
or nchar
. Second, if it’s only to specify y
or n
, You better simply use bit
, what only holds values of 0 or 1.
CREATE TABLE Example
(
[status] bit not null, -- 0 for `n`, 1 for `y`
[originalPath] varchar(70) not null, -- keeps the original value. Think write only.
[path] as (case when status = 1 then
null
else
originalPath
end) -- computed column to use in select statements. This is read only.
)
solved SQL Server constraint [closed]