Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I script SQL constraint for a number to fall within a range?

How to script a constraint on a field in a table, for an acceptable range of values is between 0 and 100?

like image 986
Macho Matt Avatar asked Dec 19 '08 20:12

Macho Matt


2 Answers

ALTER TABLE Table
ADD CONSTRAINT CK_Table_Column_Range CHECK (
   Column >= 0 AND Column <= 100 --Inclusive
)
like image 91
Mark Brackett Avatar answered Oct 28 '22 10:10

Mark Brackett


A check constraint like "fieldname BETWEEN 0 AND 100" should do it.

like image 31
dkretz Avatar answered Oct 28 '22 10:10

dkretz