Subject | Re: [firebird-support] Changing a fields |
---|---|
Author | Milan Babuskov |
Post date | 2005-07-12T12:16:26Z |
fabiano_bonin wrote:
alter table V2$CEC1 alter CODIGO type PS_CODIGO;
after backing it up.
I never do these system-tables modifications. If ALTER TABLE x ALTER
column TYPE t; does not work, you can do this:
1. create temporary column (using new datatype)
2. update table set temp = original;
3. drop original column
4. rename temp to "original" name
Of course, step 3. would fail if you have dependencies, so you might
want to drop them first and create them after step 4. If there are too
many changes, dependencies and constraints, it is often easier to create
empty database:
a) isql -x db.fdb > script.sql
b) edit script.sql and alter datatype(s).
c) isql -i script.sql
Then just pump the data and you're done.
--
Milan Babuskov
http://www.flamerobin.org
> For example, i have a field of type varchar(25), and i want to changeAs long as your changes are "compatible", you are much better off doing:
> it's type to a previously create domain, PS_CODIGO, of type varchar(50).
>
> After the change in the GUI, it runs the following script:
>
> update RDB$RELATION_FIELDS set
> RDB$FIELD_SOURCE = 'PS_CODIGO'
> where (RDB$FIELD_NAME = 'CODIGO') and
> (RDB$RELATION_NAME = 'V2$CEC1')
> ;
alter table V2$CEC1 alter CODIGO type PS_CODIGO;
> I'd like to know if i can have troubles with this sort ofYou could get database in a state where you won't be able to restore
> modification, and what kind of troubles should i expect.
after backing it up.
I never do these system-tables modifications. If ALTER TABLE x ALTER
column TYPE t; does not work, you can do this:
1. create temporary column (using new datatype)
2. update table set temp = original;
3. drop original column
4. rename temp to "original" name
Of course, step 3. would fail if you have dependencies, so you might
want to drop them first and create them after step 4. If there are too
many changes, dependencies and constraints, it is often easier to create
empty database:
a) isql -x db.fdb > script.sql
b) edit script.sql and alter datatype(s).
c) isql -i script.sql
Then just pump the data and you're done.
--
Milan Babuskov
http://www.flamerobin.org