MySQL Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback
 





Mysql Alter Add Column In First or After


Tutorials Mysql

Topic

How to Use Mysql Alter Add Column First or MySQL Alter Add Column After Statements?



Explanation


MySQL Alter Add 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)
MySQL Alter Add 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.





A Note

MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


Other Links

web hosting