Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce clause WITH [NO] CHECK to validate old values of column when CHECK constraint is created [CORE3084] #3463

Open
firebird-automations opened this issue Jul 27, 2010 · 1 comment

Comments

@firebird-automations
Copy link
Collaborator

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

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant