Mega Code Archive

 
Categories / Oracle PLSQL / Constraints
 

State a check constraint that check relation between two columns

SQL> -- State a check constraint that check the value of more than one column. SQL> -- The following example makes sure that the value of begin_ is smaller than the value of end_. SQL> SQL> create table myTable(   2    begin_   number,   3    end_     number,   4    value_   number,   5    check (begin_ < end_)   6  ); Table created. SQL> SQL> insert into myTable values(1, 3, 4); 1 row created. SQL> insert into myTable values(2000, 3, 5); insert into myTable values(2000, 3, 5) * ERROR at line 1: ORA-02290: check constraint (SYS.SYS_C004432) violated SQL> insert into myTable values(2, 3 ,6); 1 row created. SQL> SQL> select * from myTable;     BEGIN_       END_     VALUE_ ---------- ---------- ----------          1          3          4          2          3          6 SQL> SQL> drop table myTable; Table dropped. SQL> SQL>