I have a table, with
Id as the primary key.
create table Anything ( Id bigint not null primary key identity(1, 1) )
When I look at this table in
Object Explorer, I see this image of course:
As you can see, column
Id is not null.
Then I create a dummy view on this dummy table:
create view IdIsTwoView as select Id, ( case when Id = 2 then cast(1 as bit) else cast(0 as bit) end ) as IdIsTwo from Anything
But this time, in Object Explorer I see this result:
As you can see, in spite of this fact that my
case clause is all-encompassing and covers 100% of all records, and has an answer for all records, it's nullable.
Why does SQL Server have this weird behavior? And how do I force it to be not null?
P.S we have an infrastructure to generate code dynamically, and this behavior causes us trouble and we have to manually go and change all
bool? types in C# to