Home Sql Sql-functions MySQL Add Column



MySQL Add Column
Posted on: October 6, 2010 at 12:00 AM
MySQL Add Column tutorial explains you to add the column to the existing table. The table structure can be changed using 'Alter table' query.

MySQL Add Column

     

MySQL Add Column tutorial explains you to add the column to the existing table. The table structure can be changed using 'Alter table' query. You can now add the new column  in a table using add  keyword in the query.

Understand with Example

The Tutorial describes Add Column in MySQL. To understand the example, lets see all the columns and its values from table employee using select query.

 

 

 

 

Query
 select * from employee;
Output

 

+----+--------+----------------------+
| id | name   | designation          |
+----+--------+----------------------+
| 1  | Ajay   | programmer           |
| 2  | Vinay  | programmer           |
| 4  | Kamal  | sr. graphic designer |
| 5  | Rajiv  | graphic designer     |
| 6  | Nitin  | content writer       |
| 7  | Sachin | programmer           |
| 8  | Karan  | programmer           |
+----+--------+----------------------+

The Alter Table employee is used to modify the table 'employee' and add a new column 'address' to the existing table 'employee'.

ALTER TABLE employee ADD address VARCHAR(50);

Now you can see the changed table and its value by select query.

Query
 select * from employee;
Output

 

+----+--------+----------------------+--------+
| id | name   | designation          |address |
+----+--------+----------------------+--------+
| 1  | Ajay   | programmer           |        |
| 2  | Vinay  | programmer           |        |
| 4  | Kamal  | sr. graphic designer |        |
| 5  | Rajiv  | graphic designer     |        |
| 6  | Nitin  | content writer       |        |
| 7  | Sachin | programmer           |        |
| 8  | Karan  | programmer           |        |
+----+--------+----------------------+--------+

Related Tags for MySQL Add Column:


More Tutorials from this section

Ask Questions?    Discuss: MySQL Add Column  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.