Adding a NOT NULL
field
This is by far the preferred method in general, but it causes some special problems if used on a populated table, as you will see in a moment.First, add the field with the following statement:
alter table Adventures add id int not null
Or, if you want to name the constraint explicitly (this makes it easier if you ever want to drop it later):
alter table Adventures add id int constraint IdNotNull not null
Despite the NOT NULL
constraint, the new ID fields that have been added to the existing rows will all be NULL
.In this special case, Firebird allows invalid data to be present in a column.It will even write the NULL
s to a backup without complaining, but it will refuse to restore them, precisely because of the constraint violation.
Note
|
Firebird 1.5 (but not 1.0 or 2.0) even allows you to make such a column the primary key! |