TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Oracle Alter Table

Oracle Alter Table for beginners and professionals with examples on insert, select, update, delete, table, view, join, key, functions, procedures, indexes, cursor etc.

<< Back to ORACLE

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:

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.

How to add multiple columns in the existing 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));
Now, two columns customer_type and customer_address will be added in the table customers.

How to modify column of a table

Syntax:

ALTER TABLE table_name
  MODIFY column_name column_type; 

Example:

ALTER TABLE customers
  MODIFY customer_name varchar2(100) not null;
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:

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));
This will modify both the customer_name and city columns in the table. 

How to drop column of a table

Syntax:

ALTER TABLE table_name
  DROP COLUMN column_name;

Example:

ALTER TABLE customers
  DROP COLUMN customer_name;
This will drop the customer_name column from the table.

How to rename column of a table

Syntax:

ALTER TABLE table_name
  RENAME COLUMN old_name to new_name;

Example:

ALTER TABLE customers
 RENAME COLUMN customer_name to cname;
This will rename the column customer_name into cname.

How to rename table

Syntax:

ALTER TABLE table_name
  RENAME TO new_table_name; 

Example:

ALTER TABLE customers
RENAME TO retailers;
This will rename the customer table into "retailers" table. 
Next TopicOracle DROP TABLE




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf