SQL Tutorial SQL Advanced SQL Database SQL References

SQL ADD Keyword



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

Syntax

The syntax for using ADD keyword 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 SQL code is:

    ALTER TABLE Employee
    ADD EMail varchar(255);
    
    --see 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 results
    SELECT * FROM Employee;
    

    This will produce the result as shown below:

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

  • ❮ SQL Keywords

5