Subject Re: NOT NULL constraint not being enforced by Firebird
Author dr_bentonquest
> > This is a known issue.
> >
> > If you add a not null field to a table, you need to remember to set
> > values to all pre-existing records in that field. The existing records
> > are not checked when such a constraint is added. The values are
> > policed basically in before insert or update triggers.
> I've known this issue (adding not null columns WITHOUT a default value)
> and I've tried to test it yesterday. Benton metioned that he defined
the
> field with "DEFAULT 0 NOT NULL". I tried this on my system and Firebird
> behaved like it should: it pre-set the value 0 into the column.
> Here is what I did via DDL, works flawlessly:
> ALTER TABLE TESTNULLS ADD TESTFIELD NUMERIC(9,2) DEFAULT 0 NOT NULL;
>
> Benton, could it be that you added the "DEFAULT 0" later on, via some
> tool like IBExpert?

Not that I recall. I must have used a statement like ALTER TABLE
DETALLENOM ADD DEDXTRA NUMERIC(9,2) DEFAULT 0 NOT NULL.

Sincere thanks to all for your insight. I have solved the problem by
including the fields in the INSERT field list and providing a 0 as the
field value.

Best Regards,

-Benton