MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL ADD Keyword



The MySQL ADD keyword is used to add a column in an existing table.

Syntax

The syntax for using ADD keyword in MySQL is given below:

ALTER TABLE table_name
ADD column_name;

Example:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To add a new column EMail with datatype varchar(255) in the Employee table, the query is:

    ALTER TABLE Employee
    ADD EMail varchar(255);
    
    -- see the results
    SELECT * FROM Employee;
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalaryEMail
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    5RameshNew Delhi283000
    6HuangBeijing282800
  • To add a default value to the new column, DEFAULT constraint can be used. Consider the example below:

    ALTER TABLE Employee
    ADD Bonus DECIMAL(18,2) DEFAULT 1000;
    
    -- see the results
    SELECT * FROM Employee;
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalaryBonus
    1JohnLondon2530001000
    2MarryNew York2427501000
    3JoParis2728001000
    4KimAmsterdam3031001000
    5RameshNew Delhi2830001000
    6HuangBeijing2828001000

❮ MySQL Keywords