Subject Re: [firebird-support] Alter Colum to set a Default Value
Author Helen Borrie
At 06:34 PM 3/06/2010, Marius Labuschagne wrote:
>Hi,
>
>Is it possible to issue a statement to change or set the default value
>for an existing column?
>
>I have tried the following:
>alter table stock alter column StockType type varchar(20) default
>'Non-Serialised';
>
>But this does not work, it produces an error:
>Invalid token.
>Dynamic SQL Error.
>SQL error code = -104.
>Token unknown - line 1, column 59.
>default.
>
>The StockType field is already in the database table with a varchar(20)
>definition, I just need to add a default value for this field.
>
>Any help appreciated.

1. create domain some_name varchar(20) default 'Non-Serialised';
commit;
2. alter table stock alter column StockType type some_name;
commit;

Note, this does NOT magically update existing data: if you want NULLs in StockType to be changed to the default value, you will need to do it explicitly with an UPDATE statement.

./heLen