You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code sample allows to create CHECK-constraint for some table with previously entered data that violates a new requirement for them:
recreate table tmp(id int not null, val int);
insert into tmp(id,val) values (1, 123);
insert into tmp(id,val) values (2, null);
insert into tmp(id,val) values (3, 345);
alter table tmp add constraint ck_tmp_enough_val check (val > 1000);
commit;
Note that the new rule for data (val>1000) will be effectively checked only for NEW data of the column `VAL`.
Currently Firebird do NOT validate old values of this column against new rules.
It will be good if some opportunity to do this will be avaliable, i.e. force the engine to validate old values.
The clause may be like this:
alter table tmp add constraint ck_tmp_enough_store check(val > 1000) WITH CHECK
The text was updated successfully, but these errors were encountered:
I don't think any explicit clause is required. New constraints must never invalidate the database, otherwise we may get an unrestorable backup. So, ideally, the existing data should be always validated during constraint creation. The only question is how possible it is technically if the check condition is non-trivial and contains sub-queries involving other tables.
Submitted by: @pavel-zotov
The following code sample allows to create CHECK-constraint for some table with previously entered data that violates a new requirement for them:
recreate table tmp(id int not null, val int);
insert into tmp(id,val) values (1, 123);
insert into tmp(id,val) values (2, null);
insert into tmp(id,val) values (3, 345);
alter table tmp add constraint ck_tmp_enough_val check (val > 1000);
commit;
Note that the new rule for data (val>1000) will be effectively checked only for NEW data of the column `VAL`.
Currently Firebird do NOT validate old values of this column against new rules.
It will be good if some opportunity to do this will be avaliable, i.e. force the engine to validate old values.
The clause may be like this:
alter table tmp add constraint ck_tmp_enough_store check(val > 1000) WITH CHECK
The text was updated successfully, but these errors were encountered: