oracle

Thursday, 20 April 2017

SQL: Add or Delete a Column Or Change the name of Column

To add column in existing table:
Syntax:
alter table table_name add new_column_name datatype(size);


To Delete column :
Syntax:
alter table table_name drop column column_name;


For the modification of name of column in table:
we use following statement

Syntax:

alter table table_name rename column column_old_name to column_new_name;

Example:

alter table authors rename column author_id to author_loc;

Result:

table authors altered.

We can change / modify data type of column:

Syntax:

Alter table table_name modify column_name datatype(size);

Example:

alter table authors modify author_loc varchar2(100);

Result:

Altered.

No comments:

Post a Comment