Subject Re: [firebird-support] Alter column width -> shorter
Author Helen Borrie
At 12:18 PM 31/01/2008, you wrote:
>Hi,
>
>I want to change a column's data type from varchar(32) to varchar(30). -> or
>anything shorter
>As we all know, Firebird prevents this, I've also read somewhere that the
>only way is by creating new column with desired data type/column width and
>copy data manually.
>Is it true?

Yes

>is there any easier way to perform this task?

No. But it is pretty simple.

>Any comment/suggestion is greatly appreciated

When copying the data, you will need to use substring() to ensure you don't get any overflows. Of course, any values that are currently longer than 30 characters will be truncated:

update atable
set newsurname = substring (surname from 1 for 30 )

In an isql script (exclusive access, please!):

alter table atable add newsurname varchar(30);
commit;
update atable
set newsurname = substring (surname from 1 for 30);
commit;
alter table atable drop surname;
commit;
alter table atable add surname varchar(30);
commit;
update atable set surname = newsurname;
commit;
alter table drop newsurname,
alter surname position 4; <--- whatever position surname had before
commit;

./heLen