i2tutorials

MySQL – Add Column

MySQL – Add Column

 

MySQL - Add Column

The ALTER TABLE ADD COLUMN command in MySQL allows the addition of a new column to an existing table.

Syntax:

ALTER TABLE table_name   
    ADD COLUMN column_name column_definition [FIRST|AFTER existing_column];  

Example

ALTER TABLE employees
  ADD age INT NOT NULL
    AFTER last_name;

In some cases, it may be necessary to add multiple columns to an existing table. Then we can use the following syntax:

Syntax:

ALTER TABLE table_name   
    ADD COLUMN column_name1 column_definition [FIRST|AFTER existing_column],  
    ADD COLUMN column_name2 column_definition [FIRST|AFTER existing_column];  

Example:

 ALTER TABLE employee
  ADD city varchar(40) NOT NULL
    AFTER last_name,
  ADD country varchar(35) NULL
    AFTER city;

Exit mobile version