Subject Re: [firebird-support] Table modifications
Author Svein Erling Tysvaer
Make sure you have exclusive access to the table, find the name of the
primary key using

select rdb$constraint_name
from rdb$relation_constraints
where rdb$constraint_type = 'PRIMARY KEY'
and rdb$relation_name = 'Configuracion'

and then run the following script, only replacing
<NameThatTheAboveQueryReported>:

ALTER TABLE "Configuracion"
DROP CONSTRAINT <NameThatTheAboveQueryReported>;

COMMIT;

ALTER TABLE "Configuracion"
ALTER COLUMN "Item" TYPE VARCHAR(64),
ADD CONSTRAINT "PK_Configuracion" PRIMARY KEY ("Item");

COMMIT;

As you can see, I've tried to name the primary key - I find it generally
better to deliberately specify the name than to have to find what name
Firebird assigns.

HTH,
Set

Maverick Thunder wrote:
> Hi, I have a doubt (maybe this was already discussed)
>
> I create this simple table in FB 2.1
>
> CREATE TABLE "Configuracion" (
> "Item" VARCHAR(32) NOT NULL,
> "ValorTexto" VARCHAR(120) NOT NULL,
> "ValorReal" DOUBLE PRECISION NOT NULL,
> "ValorEntero" INTEGER NOT NULL
> );
>
> ALTER TABLE "Configuracion"
> ADD PRIMARY KEY ("Item");
>
> when I want to insert some records I notice that one has a longer text for field "Item" so
> I decided to change the column size from VARCHAR(32) to VARCHAR(64) but the following
> error arises:
>
> SQL Error: unsuccessful metadata update MODIFY RDB$RELATION_FIELDS failed action
> cancelled by trigger (1) to preserve data integrity Cannot update index segment used by an
> Integrity Constraint. Error Code: -607. This operation is not defined for system tables.
> The SQL:
>
> ALTER TABLE "Configuracion"
> ALTER COLUMN "Item" TYPE VARCHAR(64);
>
> The table isn't has no relationships with any other and I imagine that the "constraint" is
> the primary index. Is there a way to modify table columns without errors because, for
> e.g., converting an INTEGER column to DOUBLE PRECISION gives errors too.
>
> To resume, it is almost impossible to make changes to columns, at least, via alter table.
> How can I circumvent this?
>
> Best regards,
> Mauro H. Leggieri