Add another check constraint : Add Check Constraint « Constraints « Oracle PL / SQL






Add another check constraint


SQL> -- add a check constraint
SQL>
SQL> create table myTable (
  2    a number check (a between 0 and 100),
  3    b number
  4  );

Table created.

SQL>
SQL>
SQL> alter table myTable
  2    add constraint ch_b check (b > 50);

Table altered.

SQL>
SQL>
SQL>
SQL> insert into myTable values(1, 30);
insert into myTable values(1, 30)
*
ERROR at line 1:
ORA-02290: check constraint (SYS.CH_B) violated


SQL> insert into myTable values(2000, 300);
insert into myTable values(2000, 300)
*
ERROR at line 1:
ORA-02290: check constraint (SYS.SYS_C004428) violated


SQL> insert into myTable values(2, 3000);

1 row created.

SQL>
SQL> select * from myTable;

         A          B
---------- ----------
         2       3000

SQL>
SQL> drop table myTable;

Table dropped.

SQL>
SQL>

           
       








Related examples in the same category