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.

MySQL Add Column

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.

select * from employee;

+----+------------------------+----------------------+--------+
| 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'.

ALTER TABLE employee ADD address VARCHAR(50);

+----+------------------------+----------------------+--------+---------+
| 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  |         |
+----+------------------------+----------------------+--------+---------+