Adding constraint that checks values and prohobits nulls : NOT NULL « Constraints « Oracle PL / SQL






Adding constraint that checks values and prohobits nulls

   

SQL>
SQL> CREATE TABLE purchase (
  2       product_name  VARCHAR2(25),
  3       product_price NUMBER(4,2),
  4       purchase_date DATE
  5       );

Table created.

SQL>
SQL> ALTER TABLE purchase ADD (
  2       CONSTRAINT reasonable_date CHECK(
  3            purchase_date IS NOT NULL
  4            AND
  5            TO_CHAR(purchase_date, 'YYYY-MM-DD') >= '2000-06-30'
  6            )
  7       );

Table altered.

SQL>
SQL> INSERT INTO purchase VALUES ('Small Widget', 10, '28-FEB-00');
INSERT INTO purchase VALUES ('Small Widget', 10, '28-FEB-00')
*
ERROR at line 1:
ORA-02290: check constraint (JAVA2S.REASONABLE_DATE) violated


SQL>
SQL>
SQL>
SQL> drop table purchase;

Table dropped.

   
    
  








Related examples in the same category

1.NOT NULL Column Constraints
2.Change a column to 'not null' with null data in it
3.NOT NULL CONSTRAINT
4.Create a SQL collection type that disallows null values
5.ORA-01400: cannot insert NULL into
6.Add not null constraint to different columns
7.alter table dept modify emp_count NOT NULL