SQL ALTER Table Statement

0
27

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
SHARE
Previous articleSQL ORDER BY keyword
Next articleSQL AND & OR Operators

Hello Itsourcecoders, welcome to itsourcecode.com. I’m Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I’ve learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!

LEAVE A REPLY

Please enter your comment!
Please enter your name here