Subject | different ways to change the field type |
---|---|
Author | vincent_kwinsey |
Post date | 2007-08-31T09:33:26Z |
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...
So - what ir preferable way to change the field type? Are there any
risks connected with 2)?
Thanks!
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...
So - what ir preferable way to change the field type? Are there any
risks connected with 2)?
Thanks!