Shares
facebook sharing button Share
twitter sharing button Tweet
email sharing button Email
linkedin sharing button Share
reddit sharing button Share
tumblr sharing button Share
blogger sharing button Share
print sharing button Print
skype sharing button Share
sms sharing button Share
whatsapp sharing button Share
arrow_left sharing button
arrow_right sharing button
 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