Thread: table check constraint

table check constraint

From
Robert Schnabel
Date:
I'm trying to add range check constraints to tables but I'm not 100%
sure I'm doing it correctly for one of them.  Specifically, what do you
do if you want to allow two non-overlapping ranges?  For example, I
need to have everything (>105 AND <199) OR (>202 AND
<900).  I read in the docs that using 'between' isn't a good idea so
I did something like the following:

ALTER TABLE gen000
  ADD CONSTRAINT check000 CHECK (sample_id > 105 AND sample_id <
199 OR sample_id > 202 AND sample_id < 900);

Will this behave the way it reads or do I need to structure it
differently?

Thanks,
Bob