Subject Re: [firebird-support] Alter Colum to set a Default Value
Author Helen Borrie
At 06:34 PM 3/06/2010, Marius Labuschagne wrote:
>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
>But this does not work, it produces an error:
>Invalid token.
>Dynamic SQL Error.
>SQL error code = -104.
>Token unknown - line 1, column 59.
>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';
2. alter table stock alter column StockType type some_name;

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.