Sunday, March 11, 2018

Oracle Database ALTER Table

Hello In this post we are going to learn ALTER oracle command.

Oracle ALTER keyword is used to change properties of existing oracle object i.e. Table.

Oracle ALTER Table is used to add,modify,delete existing column of Table. We can change Database name using Oracle ALTER table keyword.

Oracle Syntax Add Single Column & Multiple Columns To Exiting Table as shown below

ALTER Table Table_Name
ADD Column_Name Datatype



ALTER Table Table_Name
ADD 
(Column_Name1 Datatype,
Column_Name2 Datatype,
Column_Name3 Datatype,
.....
.....
Column_NameN Datatype   
)

Above Add keyword is used to add new column to an existing table.



Oracle Syntax Modify Single Column & Multiple Columns To Exiting Table as shown below

ALTER Table Table_Name
MODIFY Column_Name Datatype



ALTER Table Table_Name
MODIFY 
(Column_Name1 Datatype,
Column_Name2 Datatype,
Column_Name3 Datatype,
.....
.....
Column_NameN Datatype   
)

Above Modify keyword is used to modify existing column from an existing table.



Oracle Syntax Drop Columns of an Exiting Table as shown below

ALTER Table Table_Name
DROP COLUMN Column_Name

Above Drop keyword is used to delete column of an Table.



Oracle Syntax Rename Columns of an Exiting Table as shown below

ALTER Table Table_Name
RENAME COLUMN Column_Name_Old TO Column_Name_New

Above Rename Column keyword is used to rename existing column name Column_Name_Old  to new name Column_Name_New.



Oracle Syntax Rename Existing Table Name as shown below

ALTER Table Table_Name_Old
RENAME TO Table_Name_New

Above Rename keyword is used to change existing table name Table_Name_Old to Table_Name_New.


0 comments:

Post a Comment