国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL數據庫在指定位置增加字段

2024-07-24 12:58:28
字體:
來源:轉載
供稿:網友

這個本身屬于MySQL的基本語法,我這里給出一個例子而已。

view plaincopy to clipboardPRint?
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> 
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 ]


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖远县| 菏泽市| 神农架林区| 邢台县| 新宁县| 天长市| 崇明县| 孝义市| 焉耆| 和顺县| 永登县| 常宁市| 浦县| 县级市| 甘孜县| 重庆市| 民乐县| 香格里拉县| 枣阳市| 祁门县| 建平县| 安义县| 双流县| 潮州市| 紫阳县| 理塘县| 南安市| 贡山| 雷波县| 阳高县| 马山县| 炎陵县| 上思县| 怀远县| 蓝山县| 开江县| 泸溪县| 留坝县| 平舆县| 巫山县| 博爱县|