Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
cancel
Showing results for 
Search instead for 
Did you mean: 

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