| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Unique Constraint with Multiple NULLS
> 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
![]() |
![]() |