UNIQUE and NULL in SQL

From: Brian Smith <brian-l-smith_at_uiowa.edu>
Date: 29 Dec 2001 19:28:12 -0800
Message-ID: <60360d48.0112291928.2e7c5818_at_posting.google.com>



What is the rationale for having a UNIQUE constraint treat NULLS as equal?

How can I create a UNIQUE constraint on a column that allows multiple rows to have NULL for that column:

CREATE TABLE x ( x NUMBER UNIQUE);

INSERT INTO x VALUES (1);     -- SUCCEESS
INSERT INTO x VALUES (1);     -- FAILURE
INSERT INTO x VALUES (NULL);  -- SUCCESS
INSERT INTO x VALUES (NULL);  -- FAILURE

I want the fourth insert statement above to succeed while still enforcing the UNIQUE constraint for non-null columns. Is that possible?

Thanks,
Brian Received on Sun Dec 30 2001 - 04:28:12 CET

Original text of this message