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.
Syntax:
ALTER TABLE table_name ADD column_name column-definition;
Example:
Consider that already existing table customers. Now, add a new column customer_age into the table customers.
ALTER TABLE customers ADD customer_age varchar2(50);
Now, a new column "customer_age" will be added in customers table.
Syntax:
ALTER TABLE table_name ADD (column_1 column-definition, column_2 column-definition, ... column_n column_definition);
Example
ALTER TABLE customers ADD (customer_type varchar2(50), customer_address varchar2(50));
Syntax:
ALTER TABLE table_name MODIFY column_name column_type;
Example:
ALTER TABLE customers MODIFY customer_name varchar2(100) not null;
Syntax:
ALTER TABLE table_name MODIFY (column_1 column_type, column_2 column_type, ... column_n column_type);
Example:
ALTER TABLE customers MODIFY (customer_name varchar2(100) not null, city varchar2(100));
Syntax:
ALTER TABLE table_name DROP COLUMN column_name;
Example:
ALTER TABLE customers DROP COLUMN customer_name;
Syntax:
ALTER TABLE table_name RENAME COLUMN old_name to new_name;
Example:
ALTER TABLE customers RENAME COLUMN customer_name to cname;
Syntax:
ALTER TABLE table_name RENAME TO new_table_name;
Example:
ALTER TABLE customers RENAME TO retailers;