Subject | Problem with UNIQUE |
---|---|
Author | Fulvio Senore |
Post date | 2010-12-22T12:34:32Z |
I have a table that contains (among others) the following columns:
item ID, BIGINT, not null
supplier ID, BIGINT, not null
supplier code, varchar.
the last column is the code used by the supplier for a given item. It
can be null if the user does not know it, or if he does not care.
Obviously the supplier code must be unique for each supplier, so I tried
to add an UNIQUE constraint to the last two columns, but it did not
work. If I have many rows without supplier code I have the same supplier
id in each row, and the supplier code is NULL. Firebird treats these
rows as duplicate and I cannot create the constraint.
How can I force uniqueness for supplier id and supplier code, ignoring
null supplier codes?
Thanks in advance.
Fulvio Senore
item ID, BIGINT, not null
supplier ID, BIGINT, not null
supplier code, varchar.
the last column is the code used by the supplier for a given item. It
can be null if the user does not know it, or if he does not care.
Obviously the supplier code must be unique for each supplier, so I tried
to add an UNIQUE constraint to the last two columns, but it did not
work. If I have many rows without supplier code I have the same supplier
id in each row, and the supplier code is NULL. Firebird treats these
rows as duplicate and I cannot create the constraint.
How can I force uniqueness for supplier id and supplier code, ignoring
null supplier codes?
Thanks in advance.
Fulvio Senore