0

I can't find anything in internet about setting range of column values. For example I want to add column "grade" which is 1 to 6 how can I validate this?

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • 1
    you can use check constraints to make sure values in a column are in a certain range or set of values. Or you could have a table of acceptable answers and use a foreign key to join the main table to that lookup table. – Boneist Feb 08 '19 at 10:02
  • 2
    Possible duplicate of [SQL constraint minvalue / maxvalue?](https://stackoverflow.com/questions/1736630/sql-constraint-minvalue-maxvalue) – Nico Haase Feb 08 '19 at 10:09

1 Answers1

2

You need to add a check constraint to your table. e.g:

ALTER TABLE your_table
ADD CONSTRAINT check_grade
  CHECK (grade between 1 and 6); 
Ted at ORCL.Pro
  • 1,602
  • 1
  • 7
  • 10