|
Add a column First :
We can position the field using FIRST and AFTER modifiers. The following example query will place the new field as the first field in the table.
mysql> ALTER TABLE student ADD COLUMN marks INT(10) FIRST;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc student;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| marks | int(10) | YES | | NULL | |
| studid | int(10) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| address | varchar(40) | YES | | NULL | |
| phone | int(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
Add a column After :
We can also place the new field next to any of the field. The following example query will place the new field immediately after the field name.
mysql> ALTER TABLE student ADD COLUMN marks INT(10) AFTER names;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc student;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| studid | int(10) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| marks | int(10) | YES | | NULL | |
| address | varchar(40) | YES | | NULL | |
| phone | int(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
Next we can see how to delete and change a field.
|