mysql数据库在指定位置增加字段: 本身属于mysql的基本语法,这里给出一个例子。 mysql -- 测试数据库在指定位置增加字段 mysql drop table if exists t; query ok, 0 rows affected (0.06 sec) mysql create table t(age int,address varchar(50)); query o
mysql数据库在指定位置增加字段:
本身属于mysql的基本语法,这里给出一个例子。
mysql> -- 测试数据库在指定位置增加字段
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(20) 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 first;
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>
相关的语法描述为
alter [online | offline] [ignore] table tbl_name alter_specification [, alter_specification] ...alter_specification: table_option ...
| add [column] col_name column_definition [first | after col_name ]
.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!