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 | | +----+--------+----------------------+--------+ |
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.
Ask Questions? Discuss: MySQL Add Column
Post your Comment