1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

How to impose a check that a certain field can only contain a certain domain of values?

Discussion in 'SQL - Questions and Answers' started by irfanhab, May 24, 2006.

  1. irfanhab New Member

    Dialect: Oracle
    For example consider a situation where you are storing an attribute which consists of a finite number of values such as "AM" or "PM"? How do you ensure that any other values are rejected to the concerned field?
  2. irfanhab New Member

    Dialect: Oracle
    You can use SQL's CHECK Constraints
    Consider that the field is called "timeperiod" and the table is called "day"
    SQL:

    alter table day add check (timeperiod in ('AM', 'PM'));

Share This Page