Adding Columns
Learning Outcomes
- Learn how to add a column to a table.
Supporting Materials
The following web pages may help you understand the SQL syntax in this tutorial:
Lesson Materials
There are three scenarios for adding columns to tables:
- Add a column without a
NOT NULL
constraint. - Add a column with a
NOT NULL
constraint. - Add a column with a
CHECK
constraint.
Add an optional or unconstrained column
ALTER TABLE somewhere ADD ( timbuktu VARCHAR2(30)); |
Add a mandatory or constrained column
ALTER TABLE somewhere ADD ( timbuktu VARCHAR2(30) CONSTRAINT nn_somewhere NOT NULL); |
Add an optional or unconstrained column
ALTER TABLE somewhere ADD ( price NUMBER(15,2) CONSTRAINT ck_somewhere CHECK price > 5 ); |
You have now seen the three key use cases for adding a column to a table.