Mega Code Archive

 
Categories / Oracle PLSQL / Constraints
 

Syntax for adding check constraint to a column

SQL> --CREATE TABLE <table schema> SQL> --   (key attribute NOT NULL, SQL> --    attribute        attribute type, SQL> --    attribute        attribute type SQL> --    [CHECK (<attribute value> IN (set of values))] SQL> --    PRIMARY KEY      (key attribute)); SQL> SQL> --Example: SQL> SQL> CREATE TABLE emp   2     (id         VARCHAR2(10)      NOT NULL,   3      name       VARCHAR2(20),   4      address    VARCHAR2(35),   5      emp_type   VARCHAR2(8)   6        CHECK(emp_type IN ('Designer', 'Worker')),   7      PRIMARY KEY (id)); Table created. SQL> SQL> drop table emp; Table dropped.