SQL Oracle Java JSP JDBC PHP MORE

Oracle Alter Statement

To add, delete, or modify columns in an existing table. The ALTER TABLE statement is used.

Oracle ALTER TABLE Syntax

To add a column in a table, the syntax is

ALTER TABLE table_name
ADD column_name column-datatype;

How to add multiple columns in the existing table

syntax:

ALTER TABLE table_name
ADD (column_1 column-datatype,
column_2 column-datatype,
...
column_n column_datatype);

Example:

ALTER TABLE students
ADD (student_type varchar2(40),
student_address varchar2(40));

How to modify column of a table

syntax:

ALTER TABLE table_name
MODIFY column_name column_type;

Example:

ALTER TABLE students
MODIFY student_name varchar(200) not null;

How to modify multiple columns of a table

syntax:

ALTER TABLE table_name
MODIFY (column_1 column_type,
column_2 column_type,
...
column_n column_type);

Example:

ALTER TABLE students
MODIFY (student_name varchar(200) not null,
class varchar(200));

How to rename column of a table

syntax:

ALTER TABLE table_name
RENAME COLUMN old_name to new_name;

Example:

ALTER TABLE students
RENAME COLUMN student_name to lname;