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

Home -> Community -> Usenet -> comp.databases.theory -> Re: Unique Constraint with Multiple NULLS

Re: Unique Constraint with Multiple NULLS

From: David Portas <REMOVE_BEFORE_REPLYING_dportas_at_acm.org>
Date: Thu, 1 Jan 2004 21:48:24 -0000
Message-ID: <G_2dncia7cWZCGmiRVn-uw@giganews.com>


> What is the SQL-92 standard for allowing multiple NULL values within a
> unique constraint?

A UNIQUE constraint treats NULLs in the same column as equal to each other. In other words UNIQUE(colX) will not be satisfied if colX contains more than one NULL value. This is consistent with the behaviour of other grouping operations like GROUP BY and DISTINCT.

> Besides a trigger is there any other reasonable way to enforce this
behavior
> if the RDBMS does not support it?

That depends on the feature-set of your particular RDBMS. What product are you using? You'll probably get more help if you post to a newsgroup for that specific product. If you have full SQL-92 constraints then you can use a CHECK constraint instead:

..., CHECK (NOT EXISTS

        (SELECT colX
            FROM TableName
            GROUP BY colX
            HAVING COUNT(colX)>1))

-- 
David Portas
------------
Please reply only to the newsgroup
--
Received on Thu Jan 01 2004 - 15:48:24 CST

Original text of this message

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