Home Sql Mysql-table MySQL Add Column



MySQL Add Column
Posted on: April 18, 2011 at 12:00 AM
MySQL Add Column is used to add the column to the existing table. The Alter table keyword is used to modify the table structure and add keyword is used to add the new column in a table.

MySQL Add Column

     

MySQL Add Column is used to add the column to the existing table. The Alter table keyword is used to modify the table structure and add  keyword is used to add the new column  in a table.

Understand with Example

The Tutorial describe Add Column in MySQL. To understand the example we use select query that returns the set of columns records from table employee.

Query

 select * from employee;

Output

+----+------------------------+----------------------+--------+
| id | name                   | designation          | salary |
+----+------------------------+----------------------+--------+
| 1  | Mr.sandeep kumar suman | programmer           | 6000   |
| 2  | Miss.anusmita          | programmer           | 6000   |
| 3  | Mr.ravi kant           | software developer   | 10000  |
| 4  | Mr.suman saurabh       | sr. graphic designer | 17000  |
| 5  | Mr.rakesh              | graphic designer     | 12000  |
| 6  | Mr.noor                | content writer       | 13500  |
| 7  | Mr.girish tewari       | programmer           | 5000   |
| 8  | Mr.komal choudhary     | programmer           | 5000   |
| 9  | Miss.hardeep           | technical writer     | 5000   |
| 10 | Mr.deepak mohanty      | editor               | 15000  |
| 11 | Mr.vinod kumar         | software developer   | 8500   |
| 12 | Mr.vikash              | content writer       | 8500   |
| 13 | Mr.amit raghuvanshi    | programmer           | 6000   |
| 14 | Mr.vineet bansal       | programmer           | 6000   |
| 15 | Mr.amardeep patel      | programmer           | 8000   |
| 16 | Mr.santosh kashyap     | graphic designer     | 7500   |
| 17 | Mr.govind              | technical writer     | 6000   |
| 18 | Mr.vimlaksha gautam    | technical writer     | 15000  |
+----+------------------------+----------------------+--------+

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

Query

ALTER TABLE employee ADD address VARCHAR(50);
Output
+----+------------------------+----------------------+--------+---------+
| id | name                   | designation          | salary | address |
+----+------------------------+----------------------+--------+---------+
| 1  | Mr.sandeep kumar suman | programmer           | 6000   |         |
| 2  | Miss.anusmita          | programmer           | 6000   |         |
| 3  | Mr.ravi kant           | software developer   | 10000  |         |
| 4  | Mr.suman saurabh       | sr. graphic designer | 17000  |         |
| 5  | Mr.rakesh              | graphic designer     | 12000  |         |
| 6  | Mr.noor                | content writer       | 13500  |         |
| 7  | Mr.girish tewari       | programmer           | 5000   |         |
| 8  | Mr.komal choudhary     | programmer           | 5000   |         |
| 9  | Miss.hardeep           | technical writer     | 5000   |         |
| 10 | Mr.deepak mohanty      | editor               | 15000  |         |
| 11 | Mr.vinod kumar         | software developer   | 8500   |         |
| 12 | Mr.vikash              | content writer       | 8500   |         |
| 13 | Mr.amit raghuvanshi    | programmer           | 6000   |         |
| 14 | Mr.vineet bansal       | programmer           | 6000   |         |
| 15 | Mr.amardeep patel      | programmer           | 8000   |         |
| 16 | Mr.saurabh             | technical writer     | 5000   |         |
| 17 | Mr.santosh kashyap     | graphic designer     | 7500   |         |
| 18 | Mr.govind              | technical writer     | 6000   |         |
| 19 | Mr.vimlaksha gautam    | technical writer     | 15000  |         |
+----+------------------------+----------------------+--------+---------+

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.