Subject Re: [firebird-support] avoiding duplicates
Author Ann W. Harrison
Jason Dodson wrote:
>
> Add a check constraint:
>
> Alter Table Company
> Add Constraint CK_NAME Check (Not Exists (Select Distinct Upper(Name)
> from Company));

Being the well known mistress of the inexact syntax, I probably should
not point out that the syntax listed doesn't work... but...

Alter table Company
Add constraint CK_NAME check (not exists (select first 1 c2.name from
company c2 where upper (c2.name) = upper (name)));

The cost of that operation goes up directly with the number of records
in the table as the upper operation can not use an index. You have to
read the entire table to store a record. Not good.
>
> Now, I would imagine on a rather large table, this would get slower to
> store as the record number increased, but it saves you from doing
> something silly.... like adding an UPPER field and denormalizing your
> database.

Being (in addition to sloppy with syntax) something of a pedant, I'd
like to know which rule of normalization is violated by adding an upper
field to the table.

Cheers,

Ann