• Sean Lange (12/18/2014)


    Good question. Let's not forget that this is NOT a real representation of a boolean. A bit in sql server can have 3 values with NULL being the third.

    It actually is a real representation of a boolean. Being able to be NULL instead of having a value is an inherent property of booleans in the real world (and also in the world of mathematics).

    As far as booleans are concerned there are two values that they can have. It's also possible that for a particular boolean you don't know the value. That is represented n SQL by an SQL value not constrained not to be null. Of course there are times when one wants to refer to a boolean value where the value, whatever it may be, will always be known. This can of course be expressed perfectly well an attribute or a row in a table, using the bit type qualified by NOT NULL , but can't be expressed for an SQL local variable (local variablies are a bit of a pigs breakfast in SQL semantics for that reason amongst others).

    So SQL has two different sorts of bits: both sorts have two values, and only two values, so as far as their values are concerned they are real representations of a boolean value. One of those two sorts is such that it is always known what its value is, so is what one might call an ideal boolean. The other is a the real world boolean, which admits the possiblility that at any given time the value may not be known.

    So I don't think that it's realistic to say that bit is not a real representation of a boolean.

    There are some rather nice examples of boolean values that are unknown in mathematics: for example suppose F is a partial recursive function, P is the proposition "if F is applied to 0 at 1.00 am using a computer capable of 10**10 Mflop/s the computation will terminate by 5pm this afternoon". The tructh value for proposition is a boolean, it is either true or false, but it may be impossible to determine which it is before someone has tried the experiment. So until the question has been resolved by experiment, the value is unknown and SQL will correctly represent that situation by responding NULL instead of delivering a 1 or 0 value to a request for the value of P until such time as the experiment has been carried out and the result inserted into the database. And there are nastier examples: suppose the proporsition is "if F is applied to 0 the computation will eventually terminate with a valid result provided enough computational power is supplied for enough time"; it is a proven fact of computational theory (since over three quarters of a century ago) that for some values of F the value of the corresponding proposition P can never be known unless P is true, and it can only be known that it's true if someone has actualy carried out the computation and it terminated with a valid result, and it is impossible in general to determine whether any particular F is or is not such an F (independent proofs were made by Gödel - the incompleteness theorem - and Turing - the halting problem - and by others), so a proper representation of a boolean must allow it to be NULL instead of having a value unless there are very solid grounds for claiming that its value is always known.

    Tom