Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I max value and min value for a number data type in the creation of a table in oracle

I want to set score number to be maximum 100 and minimum 0. Am I right with just giving score number 3 placements, 3 digits and that is already enough as long as I don't looks for a number larger than 100 with NO decimal places.

create table grades (
S varchar2(12),
C varchar2(10),
Score number(3),
Letter_Grade char(1)
Constraint PK_grades Primary Key (S)
)
like image 787
GivenPie Avatar asked Nov 01 '25 15:11

GivenPie


2 Answers

You need to use a check constraint:

create table myTable (
      a number check (a between 0 and 100),
      b number
    );
like image 73
Jordan Parmer Avatar answered Nov 04 '25 04:11

Jordan Parmer


Do you want to allow decimal places? If not specify the precision too

Score number(3, 0),

The other thing is, number(3) will allow a range of -999 to 999. So you need to add a check constraint. Something like this

constraint CK_grades check ( score between 0 and 100 )
like image 44
APC Avatar answered Nov 04 '25 02:11

APC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!