Subject | Re: [firebird-support] Unique Constraints and NULLs |
---|---|
Author | Thomas Steinmaurer |
Post date | 2019-07-12T14:28:45Z |
Hello,
What you could do is to declare your column as NOT NULL and provide a
DEFAULT value/clause for your column, using a value which your
application interprets as unknown / unset etc ...
--
With regards,
Thomas Steinmaurer
http://www.upscene.com/
Professional Tools and Services for Firebird
FB TraceManager, IB LogManager, Database Health Check, Tuning etc.
> Are NULLs considered values for unique constraints on a table?No. NULL is not evaluated as part of a unique constraint.
What you could do is to declare your column as NOT NULL and provide a
DEFAULT value/clause for your column, using a value which your
application interprets as unknown / unset etc ...
--
With regards,
Thomas Steinmaurer
http://www.upscene.com/
Professional Tools and Services for Firebird
FB TraceManager, IB LogManager, Database Health Check, Tuning etc.
>
> e.g.
>
> CREATE TABLE blah (
> col1 INT NOT NULL,
> col2 INT,
>
> CONSTRAINT unq_blah UNIQUE(col1, col2)
> );
>
> INSERT INTO blah (col1, col2) (123, 321);
> INSERT INTO blah (col1, col2) (123, 999); /* okay */
> INSERT INTO blah (col1, col2) (123, 321); /* error */
>
> INSERT INTO blah (col1, col2) (123, NULL);
> INSERT INTO blah (col1, col2) (123, NULL); /* okay? error? */
>
> I'd like that NULL example to be an error, does the UNIQUE constraint do
> that, or do I have to use a CHECK constraint? If it does require the
> CHECK, are there any performance tips for that setup?
>
> Scott
>
>
>
> ------------------------------------
> Posted by: Scott Morgan <blumf@...>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Documentation item
> on the main (top) menu. Try FAQ and other links from the left-side menu there.
>
> Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ------------------------------------
>
> Yahoo Groups Links
>
>
>