1751920 Members
5265 Online
108783 Solutions
New Discussion юеВ

Column value restriction

 
SOLVED
Go to solution
Manuel G
Frequent Advisor

Column value restriction

Hi all:

Is there any way to restrict a table column to a group of values?

Example: I want column values to be 0 or 1 and any more, and I want Oracle to give an error if this clause is violated.

Thanks in advance.
2 REPLIES 2
Ian Lochray
Respected Contributor
Solution

Re: Column value restriction

When you create or alter your table, you can give a column a "check constraint". For example:
create table abc (col1 NUMBER CONSTRAINT check_col1 CHECK(col1 BETWEEN 0 AND 1));
Steve Lewis
Honored Contributor

Re: Column value restriction

SVRMGR> create table sjl ( i integer check (i in (0,1)));
Statement processed.
SVRMGR> insert into sjl values (2);
ORA-02290: check constraint (SYS.SYS_C0035076) violated
SVRMGR> insert into sjl values (0);
1 row processed.