Slavomir Skopalik <skopa...@elektlabs.cz> wrote Wed, 12 Oct 2016 03:32:56  
+0300:

> Hi all,
>
> If I have a table that contains some rows, in FB3.0.1 is not possible to
> add new NOT NULL column.
>
> Example:
>
> ALTER TABLE Defects ADD idDefectType TLongInt NOT NULL;
>
> COMMIT;
>
> Cannot commit transaction:
> unsuccessful metadata update.
> Cannot make field IDDEFECTTYPE of table DEFECTS NOT NULL because there
> are NULLs present.
>
> If I will try to set a value it will causes:
>
> ALTER TABLE Defects ADD idDefectType TLongInt NOT NULL;
> update Defects SET idDefectType=0;
>
> Dynamic SQL Error.
> SQL error code = -206.
> Column unknown.
> IDDEFECTTYPE.
> At line 1, column 20.
>
> Is it bug or is it expected?
>
> Slavek
>
>



This is not a bug. On the contrary, the introduction of such restrictions  
is to fix an old bug. The fact that the addition of a field with a NOT  
NULL constraint to non-empty table violates the consistency of the  
database. You must use the following statement:

ALTER TABLE Defects
ADD idDefectType TLongInt DEFAULT 0 NOT NULL;

-- 
Simonov Denis


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to