Subject Re: [firebird-support] Can't set DEFAULT for a field value on Table CREATE.
Author Thomas Steinmaurer
Hi Paul,

> Puzzling one - running Ubuntu 10.10 - Maverick Meerkat. Using
> 2.5.1 embedded server. Run isql - can create databases and perform
> selects with no problems.
>
> However, when I try to run
>
> =================================
> CREATE TABLE MY_TABLE (
> TABLE_KEY INTEGER NOT NULL,
> TABLE_VALUE INTEGER NOT NULL DEFAULT 0,
> CONSTRAINT MY_TABLE_PK PRIMARY KEY
> (TABLE_KEY));
> ====================================
>
> I get the error
>
> ======================================
> Statement failed, SQLSTATE = 42000
> Dynamic SQL Error
> -SQL error code = -104
> -Token unknown - line 3, column 32
> -DEFAULT
> ========================
>
> It's not recognising the DEFAULT keyword?
>
> When I run the statement without the "DEFAULT 0" it
> runs smoothly.
>
> Is there a problem with DEFAULT in 2.5.1 or am I missing
> something obvious?

The latter. ;-)

The DEFAULT clause needs to be before the NOT NULL part. The following
should work fine:

CREATE TABLE MY_TABLE (
TABLE_KEY INTEGER NOT NULL,
TABLE_VALUE INTEGER DEFAULT 0 NOT NULL,
CONSTRAINT MY_TABLE_PK PRIMARY KEY
(TABLE_KEY));


HTH.

--
With regards,
Thomas Steinmaurer (^TS^)
Firebird Technology Evangelist

http://www.upscene.com/
http://www.firebirdsql.org/en/firebird-foundation/