Subject Re: [firebird-support] different ways to change the field type
Author Milan Babuskov
vincent_kwinsey wrote:
> 1) The usual way to change field type is:
> alter table... alter... type new_type;
>
> 2) But other way - which - by the way - is widely used by IBExpert
> for database comparisons is the following:
>
> assume: DOCUMENTS.TOTAL is of type domain_money (e.g. numeric(15.4))
> and it should be changed to domain_moneyext (numeric(15.6)), then 3
> SQL's do the job:
>
> ALTER TABLE DOCUMENTS ADD IBCTEMP DOMAIN_MONEYEXT;
>
> UPDATE RDB$RELATION_FIELDS SET RDB$FIELD_SOURCE=
> (SELECT R.RDB$FIELD_SOURCE FROM RDB$RELATION_FIELDS R
> WHERE R.RDB$RELATION_NAME = 'DOCUMENTS' AND
> R.RDB$FIELD_NAME='IBCTEMP')
> WHERE RDB$FIELD_NAME='TOTAL' AND RDB$RELATION_NAME='DOCUMENTS';
>
> ALTER TABLE DOCUMENTS DROP IBCTEMP;
>
> This looks a bit dirty - but it works (changes are preserved during
> backup, restore), it doesn't require to comment/drop all the
> procedures or triggers that use documents.total (and it is really
> nice, if it is heavy used field) and - at last - it is used by solid
> DB tool...

With Flamerobin there's the "Generate rebuild script" option that does
all the dropping, commenting and re-creating for you.

> So - what ir preferable way to change the field type? Are there any
> risks connected with 2)?

In this case where you replace domain with another domain, there aren't
any risks that I'm aware of (at least, not for Firebird versions 1.x and
2.0).

--
Milan Babuskov
http://fbexport.sourceforge.net