首頁 > 資料庫 > mysql教程 > Mysql中对表字段的增删改查_MySQL

Mysql中对表字段的增删改查_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-01 13:29:44
原創
852 人瀏覽過

bitsCN.com

Mysql中对表字段的增删改查

 

mysql中对表字段的增加,修改(修改类型),删除,排序

 

1.建立一个new 表,表中字段:学号,姓名,年龄。mysql> create table new (ne_id int(10),ne_name varchar(20),ne_age int(12));Query OK, 0 rows affected (0.97 sec)2.表的结构图mysql> desc new;+---------+-------------+------+-----+---------+-------+| Field   | Type        | Null | Key | Default | Extra |+---------+-------------+------+-----+---------+-------+| ne_id   | int(10)     | YES  |     | NULL    |       || ne_name | varchar(20) | YES  |     | NULL    |       || ne_age  | int(12)     | YES  |     | NULL    |       |+---------+-------------+------+-----+---------+-------+ rows in set (0.01 sec)3.向new 表中添加一个地址mysql> alter table new add ne_address varchar(20);Query OK, 0 rows affected (1.28 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc new;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| ne_id      | int(10)     | YES  |     | NULL    |       || ne_name    | varchar(20) | YES  |     | NULL    |       || ne_age     | int(12)     | YES  |     | NULL    |       || ne_address | varchar(20) | YES  |     | NULL    |       |+------------+-------------+------+-----+---------+-------+rows in set (0.00 sec)4.将字段名ne_id 改名为 ne_normysql> alter table new change ne_id ne_nor int(10);Query OK, 0 rows affected (0.22 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc new;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| ne_nor     | int(10)     | YES  |     | NULL    |       || ne_name    | varchar(20) | YES  |     | NULL    |       || ne_age     | int(12)     | YES  |     | NULL    |       || ne_address | varchar(20) | YES  |     | NULL    |       |+------------+-------------+------+-----+---------+-------+4 rows in set (0.00 sec)5.删除字段ne_nor mysql> alter table new drop ne_nor;Query OK, 0 rows affected (1.04 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc new;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| ne_name    | varchar(20) | YES  |     | NULL    |       || ne_age     | int(12)     | YES  |     | NULL    |       || ne_address | varchar(20) | YES  |     | NULL    |       |+------------+-------------+------+-----+---------+-------+3 rows in set (0.00 sec)6.修改字段类型:将ne_age 的 int 改为 varcharmysql> alter table new modify ne_age varchar(20);Query OK, 0 rows affected (1.34 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc new;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| ne_name    | varchar(20) | YES  |     | NULL    |       || ne_age     | varchar(20) | YES  |     | NULL    |       || ne_address | varchar(20) | YES  |     | NULL    |       |+------------+-------------+------+-----+---------+-------+3 rows in set (0.01 sec)7.排序mysql> alter table new modify ne_age varchar(20) after ne_address;Query OK, 0 rows affected (0.98 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> desc new;+------------+-------------+------+-----+---------+-------+| Field      | Type        | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| ne_name    | varchar(20) | YES  |     | NULL    |       || ne_address | varchar(20) | YES  |     | NULL    |       || ne_age     | varchar(20) | YES  |     | NULL    |       |+------------+-------------+------+-----+---------+-------+3 rows in set (0.00 sec)
登入後複製

 


bitsCN.com
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
linux安裝mysql報錯
來自於 1970-01-01 08:00:00
0
0
0
mysql 升級後無法重新啟動mysql服務的問題
來自於 1970-01-01 08:00:00
0
0
0
MySQL停止進程
來自於 1970-01-01 08:00:00
0
0
0
phpstudy不能啟動mysql?
來自於 1970-01-01 08:00:00
0
0
0
環境中mysql
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板