Subject Re: [firebird-support] UNQ problems ...
Author Helen Borrie
At 06:20 AM 11/05/2010, you wrote:
>I´ve a table defined as:
>
>CREATE TABLE CORRESPONDENCIA_FARMACLICK (
> CODIGO_PLAN D_CODIGO_PLAN NOT NULL,
> CODIGO_REGIMEN D_CODIGO_REGIMEN NOT NULL,
> CODIGO_PLAN_FARMACLICK SMALLINT
>);
>
>ALTER TABLE CORRESPONDENCIA_FARMACLICK ADD CONSTRAINT
>PK_CORRESPONDENCIA_FARMACLICK PRIMARY KEY (CODIGO_PLAN, CODIGO_REGIMEN);
>
>Actual data is:
>
>CODIGO_PLAN CODIGO_REGIMEN CODIGO_PLAN_FARMACLICK
>1 1 2
>1 9 12
>2 3 6
>2 8 17
>3 1 11
>3 5 3
>3 6 19
>3 7 18
>4 2 4
>4 4 5
>
>Now, the following statement:
>
>ALTER TABLE CORRESPONDENCIA_FARMACLICK ADD CONSTRAINT
>UNQ1_CORRESPONDENCIA_FARMACLICK UNIQUE (CODIGO_PLAN_FARMACLICK);
>
>produces:
>
>Invalid insert or update value(s): object columns are
>constrained - no 2 table rows can have duplicate column values.
>attempt to store duplicate value (visible to active transactions) in
>unique index "UNQ1_CORRESPONDENCIA_FARMACLICK".
>
>There are no other users connected, and I´m even restarted Firebird with
>same results.
>
>Using Firebird 2.1.1 on Ubuntu Server 9.04
>
>Am I missing something?

It means the engine cannot build the unique index, because you already have duplicates in the column CODIGO_PLAN_FARMACLICK.

I notice CODIGO_PLAN_FARMACLICK is smallint. Do you realise that a UNIQUE constraint on that column will limit your table to 32K rows?

./hb