Krivalar Tutorials 
Krivalar Tutorials



SQL ALTER TABLE CHANGE Command

<<Previous - SQL ALTER TABLE MODIFY

Next - SQL Rename Table>>






SQL ALTER TABLE statement is used to alter the structure of the table. By using this ALTER TABLE, you can add, delete or modify the column of the existing table.


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)

The syntax to rename the column name and its definition in the existing table.

ALTER TABLE  table-name CHANGE old-column-name new-colunm-name data-type;

For example, consider the above [student] table in which we want to rename the colunm name [City] into colunm name [Address]. Following is the query to remane the old colunm name into new one.

mysql> ALTER TABLE student CHANGE City Address varchar(20);
Query OK, 0 rows affected (0.42 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    |       |
| Address | varchar(20) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.11 sec)

<<Previous - ALTER TABLE MODIFY

Next - SQL Rename Table>>









Searching using Binary Search Tree