Sunday, November 25, 2012

SQL Query Add new Column Existing Table

The SQL ALTER TABLE statement allows you to rename an existing table. It can also be used to add, modify, or drop a column from an existing table.

SQL ALTER TABLE - Renaming a table

To rename a table, the SQL ALTER TABLE syntax is:
ALTER TABLE table_name
  RENAME TO new_table_name;
For example:
ALTER TABLE suppliers
  RENAME TO vendors;
This will rename the suppliers table to vendors.

SQL ALTER TABLE - Adding column(s) to a table

Syntax #1
To add a column to an existing table, the SQL ALTER TABLE syntax is:
ALTER TABLE table_name
  ADD column_name column-definition;
For example:
ALTER TABLE supplier
  ADD supplier_name varchar2(50);
This will add a column called supplier_name to the supplier table.