SQL Alter Table - Adding a column to existing table
Next - SQL Alter Table Drop Column>>
SQL ALTER TABLE statement is used to modify or change the structure of the table. By using this ALTER TABLE, you can add, delete or modify the column of the existing table.
SQL ALTER TABLE ADD column - Syntax
The following syntax is used to add new column into the existing table.
ALTER TABLE table-name ADD column-name data-type;
Following is the example SQL query to add a new column [dept] into [student] table.
mysql> ALTER TABLE student ADD Dept char(10); Query OK, 0 rows affected (1.55 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> desc student; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | RollNo | int | YES | | NULL | | | Name | varchar(20) | YES | | NULL | | | Age | int | YES | | NULL | | | City | char(20) | YES | | NULL | | | Dept | char(10) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 5 rows in set (0.14 sec)
ALTER TABLE MODIFY column type and other attributes
ALTER TABLE CHANGE existing-column-name new-column-name
Next - SQL Alter Table Drop Column>>