Subject Re: [firebird-support] Alter column not null with constraint name FB3
Author Mark Rotteveel
On 24-4-2018 15:40, Mark Rotteveel mark@...
[firebird-support] wrote:
> On 24-4-2018 09:34, liviuslivius liviuslivius@...
> [firebird-support] wrote:
>>
>>
>> Hi,
>> I need to add Field not null constraint with my custom name.
>> in previous versions of Firebird we can do:
>> 1. ALTER TABLE XXX ADD FIELDX INTEGER CONSTRAINT NK_XXX__FIELDX NOT NULL;
>
> Interestingly, that syntax is not documented in the Firebird 2.5
> language reference.
>
>> 2. UPDATE TABLE XXX SET FIELDX=some calculations;
>> Now in Firebird 3 this is prohibited on table with data.
>
> It is prohibited, unless you apply a default.
>
>> Then i do this on FB3.
>> 1. ALTER TABLE XXX ADD FIELDX INTEGER;
>> 2. UPDATE TABLE XXX SET FIELDX=some calculations;
>> 3. Add not null - how? I see only ALTER TABLE XXX ALTER FIELDX SET NOT
>> NULL; there are not place for constraint name
>> i need to add Field not null constraint with my custom name.
>
> alter table xxx add constraint NK_XXX__FIELDX check (fieldx is NOT NULL)
>
> Internally, a `not null`-constraint is just a check constraint.

Correction, I was mistaken, and this is not true. It will have
equivalent behavior, but it is not 100% the same. In any case, the
option to define a named NOT NULL constraint seems to be an undocumented
oddity of the alter table syntax.

Mark

--
Mark Rotteveel