ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

SQL ALTER Table Statement

Using ALTER Table Statement, we were able to Add, Delete or Modify Columns in an existing table.

 

Syntax to add a column:

  1. ALTER TABLE<Table-Name>
  2. ADD <Field Name> <Type> (width);

 

Syntax to drop a column :

  1. ALTER TABLE <Table-Name>
  2. DROP COLUMN <Field Name> <Type> (width);

 

Example:

  1. CREATE TABLE Employee
  2.  (
  3.   Employee_id int,
  4.   Name varchar(20),
  5.   Address varchar(50)
  6. );

 

Employee

 

Employee_id Name Address

 

 

Now, suppose you want to add a column for designation. You can do so in the following way.

  1. ALTER TABLE Employee
  2. (
  3.   ADD Designation varchar(10)
  4. );

 

Employee_id Name Address Designation

 

 

Now if you want to delete the address column, you can do this in the following way.

  1. ALTER TABLE Employee
  2. (
  3. DROP COLUMN Address
  4. );

 

The final table will look like

Employee_id Name Designation

 

 

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!