Oracle ALTER TABLE Statement

In Oracle, ALTER TABLE statement specifies how to add, modify, drop or delete columns in a table. It is also used to rename a table.

How to add column in a table

Syntax:

Example:

Consider that already existing table customers. Now, add a new column customer_age into the table customers.

Now, a new column "customer_age" will be added in customers table.

How to add multiple columns in the existing table

Syntax:

Example

Now, two columns customer_type and customer_address will be added in the table customers.

How to modify column of a table

Syntax:

Example:

Now the column column_name in the customers table is modified
to varchar2 (100) and forced the column to not allow null values. 

How to modify multiple columns of a table

Syntax:

Example:

This will modify both the customer_name and city columns in the table. 

How to drop column of a table

Syntax:

Example:

This will drop the customer_name column from the table.

How to rename column of a table

Syntax:

Example:

This will rename the column customer_name into cname.

How to rename table

Syntax:

Example:

This will rename the customer table into "retailers" table. 




Latest Courses