Search code examples
oracle-databasenumberscreate-table

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)
)

Solution

  • You need to use a check constraint:

    create table myTable (
          a number check (a between 0 and 100),
          b number
        );