Friday, February 18, 2011

A game of Truth and Falsehood ?

Here's a quick quiz for you. I create the following table:
CREATE TABLE t_truth
  (truth_id   NUMBER NOT NULL,
  dare_id     NUMBER,
  CONSTRAINT truth_dare_id CHECK (truth_id = dare_id));

Which of the following statements will successfully insert a row into the table.

INSERT INTO t_truth VALUES (1,null);
INSERT INTO t_truth VALUES (2,2);
INSERT INTO t_truth VALUES (3,0);


.
.
.
.
.
.

Actually both the first and second statements succeed.

The check constraint condition "truth_id = date_id" will evaluate to unknown when dare_id is null. The constraint is only violated if the condition fails.

1 comment:

Hemant K Chitale said...

The evil of 3-valued logic strikes again !


Hemant K Chitale