Subject | Re: [firebird-support] Problem with UNIQUE |
---|---|
Author | Paul Vinkenoog |
Post date | 2010-12-22T13:20:16Z |
Mark Rotteveel wrote:
NULL
NULL
NULL
is allowed, but with a compound one:
3 NULL
3 NULL
3 NULL
is not allowed - even though all NULLs are considered unequal.
Fulvio, I think the best way to solve this is with a trigger. Check
if the supplier code is NULL and if so, let it pass. If not, check
if the same combination of supplier ID and supplier code already
exists in the table. If so, raise an exception.
Cheers,
Paul Vinkenoog
> If I read http://www.firebirdsql.org/manual/nullguide-keys.html correctly, you can't. UNIQUE keys will allow multiple compound keys with all columns in the key NULL, but combinations containing non-NULL and NULL columns are considered unique and you cannot add more than one.Yes, it's very illogical. With a single unique key:
NULL
NULL
NULL
is allowed, but with a compound one:
3 NULL
3 NULL
3 NULL
is not allowed - even though all NULLs are considered unequal.
Fulvio, I think the best way to solve this is with a trigger. Check
if the supplier code is NULL and if so, let it pass. If not, check
if the same combination of supplier ID and supplier code already
exists in the table. If so, raise an exception.
Cheers,
Paul Vinkenoog