Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> UNIQUE and NULL in SQL

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@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 Sat Dec 29 2001 - 21:28:12 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US