Adding a Column

The following example uses ALTER TABLE to add an INTEGER column:


CREATE TABLE myTable(
  id            INTEGER CONSTRAINT my_pk PRIMARY KEY,
  status        VARCHAR2(10),
  last_modified DATE DEFAULT SYSDATE
);

SQL> ALTER TABLE myTable
  2  ADD new_Column INTEGER;

Table altered.

SQL> desc myTable;
 Name                                      Null?    Type
 ----------------------------------------- -------- -----------------
 ID                                        NOT NULL NUMBER(38)
 STATUS                                             VARCHAR2(10)
 LAST_MODIFIED                                      DATE
 NEW_COLUMN                                         NUMBER(38)

SQL>

The next example adds another column:


SQL> ALTER TABLE myTable
  2  ADD when_to_start DATE DEFAULT SYSDATE NOT NULL;

Table altered.

SQL>
SQL>
SQL> DESCRIBE myTable
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------
 ID                                        NOT NULL NUMBER(38)
 STATUS                                             VARCHAR2(10)
 LAST_MODIFIED                                      DATE
 NEW_COLUMN                                         NUMBER(38)
 WHEN_TO_START                             NOT NULL DATE

SQL>
Home »
Oracle »
Table » 

Column:
  1. Adding a Column
  2. Adding a Virtual Column
  3. Changing the Size of a Column
  4. Changing the Precision of a Numeric Column
  5. Changing the Data Type of a Column
  6. Changing the Default Value of a Column
  7. Dropping a Column
Related: