Subject | Re: [firebird-support] different ways to change the field type |
---|---|
Author | Milan Babuskov |
Post date | 2007-09-03T16:29:09Z |
vincent_kwinsey wrote:
all the dropping, commenting and re-creating for you.
any risks that I'm aware of (at least, not for Firebird versions 1.x and
2.0).
--
Milan Babuskov
http://fbexport.sourceforge.net
> 1) The usual way to change field type is:With Flamerobin there's the "Generate rebuild script" option that does
> 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...
all the dropping, commenting and re-creating for you.
> So - what ir preferable way to change the field type? Are there anyIn this case where you replace domain with another domain, there aren't
> risks connected with 2)?
any risks that I'm aware of (at least, not for Firebird versions 1.x and
2.0).
--
Milan Babuskov
http://fbexport.sourceforge.net