How to alter tables preserving default values. A trick
In certain cases I've observed that DEFAULT
and NOT NULL
values for columns seem sticky to a certain table, you cannot get ride of them when altering a field's definition using ALTER TABLE
+ ALTER COLUMN
, that is the procedure used internally in CUTE's GUI.
This is a certainly direct trick I've found this issue. Is really reconstruct the field, no more, no less. But it is. Use the SQL editor in table mode following this SQL sequence:
ALTER TABLE [the_table_in_question] ADD tmp_column new_column_type UPDATE [the_table_in_question] SET tmp_column = the_column_I_wanna_change ALTER TABLE [the_table_in_question] DROP COLUMN the_column_I_wanna_change ALTER TABLE [the_table_in_question] ADD the_column_I_wanna_change new_column_type UPDATE [the_table_in_question] SET the_column_I_wanna_change = tmp_column ALTER TABLE [the_table_in_question] DROP COLUMN tmp_column
Simply substitute in the previous sequence of SQL commands
- the_table_in_question for the name of your table.
- the_column_I_wanna_change for the name of your column.
- new_column_type for the new type you want for that column.
Take into consideration that if the table is altered during the above sequence things can turn a little problematic.