Mega Code Archive

 
Categories / Oracle PLSQL / Table
 

Create table with column having the default value

SQL> CREATE TABLE order_status (   2    order_status_id INTEGER,   3    status VARCHAR2(20) DEFAULT 'Order placed' NOT NULL,   4    last_modified DATE DEFAULT SYSDATE   5  ); Table created. SQL> SQL> SQL> --Override the defaults by specifying a value for the columns SQL> SQL> INSERT INTO order_status (order_status_id, status, last_modified)   2                    VALUES (2, 'Order shipped', to_date('19960917','YYYYMMDD')); 1 row created. SQL> SQL> INSERT INTO order_status (order_status_id)   2                    VALUES (2 ); 1 row created. SQL> SQL> SQL> SQL> SELECT * FROM order_status; ORDER_STATUS_ID STATUS               LAST_MODIFI --------------- -------------------- -----------               2 Order shipped        1996-SEP-17               2 Order placed         2006-SEP-17 SQL> SQL> drop table order_status; Table dropped. SQL> SQL> SQL>