Subject Re: [firebird-support] Changing Primary Key datatype
Author Helen Borrie
At 08:01 AM 13/07/2003 +0000, you wrote:
>Is it possible to change a PK datatype from SMALLINT to INTEGER?

It's possible to change a smallint column to an integer.


>I've though I'd removed all the dependants,

What do you mean here? what did you remove and how did you do it?

>but get an error
>messages like...
>
>ALTER TABLE CATEGORY3 drop constraint INTEG_101;
>// $$ ******** ERROR ************* $$
>//FAILED - unsuccessful metadata update
>//ERASE RDB$RELATION_CONSTRAINTS failed
>//action cancelled by trigger (1) to preserve data integrity
>//Cannot delete PRIMARY KEY being used in FOREIGN KEY
>definition.

It just means there is still at least one table that has a foreign key
pointing to this primary key.

>
>//
>commit;
>
>SET term ^;
>
>ALTER TABLE CATEGORY3
>ALTER COLUMN CAT3NO TYPE INTEGER^
>// $$ ******** ERROR ************* $$
>//FAILED - 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

The order of dependency removal is:
1 - remove the foreign key constraint(s) first and commit
2 - Then remove the primary key constraint and commit
3. Next do ALTER COLUMN on all of the affected columns and commit

After that, do
4. Re-add the primary key constraint and commit
5 Re-add the foreign key constraint and commit

heLen