Database tutorial Adding fields at specified locations
MySQL Tutorial >-Database Adding fields at specified locations
Mysql> drop table if exists t;
Query OK, 0 rows affected (0.06 sec)
Mysql> CREATE TABLE T (age int,address varchar (50));
Query OK, 0 rows affected (0.06 sec)
Mysql> desc t;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Age | Int (11) | YES | | NULL | |
| Address | varchar (50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
2 rows in Set (0.02 sec)
Mysql> ALTER TABLE t add column name varchar after age;
Query OK, 0 rows affected (0.16 sec)
records:0 duplicates:0 warnings:0
Mysql> desc t;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Age | Int (11) | YES | | NULL | |
| name | varchar (20) | YES | | NULL | |
| Address | varchar (50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 Rows in Set (0.00 sec)
Mysql> ALTER TABLE t add column ID int A;
Query OK, 0 rows affected (0.13 sec)
records:0 duplicates:0 warnings:0
Mysql> desc t;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| ID | Int (11) | YES | | NULL | |
| Age | Int (11) | YES | | NULL | |
| name | varchar (20) | YES | | NULL | |
| Address | varchar (50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in Set (0.00 sec)
Mysql>