Mysql中对表字段的增删改查_MySQL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Mysql中对表字段的增删改查_MySQL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3880字,纯文字阅读大概需要6分钟。
内容图文
![Mysql中对表字段的增删改查_MySQL](/upload/InfoBanner/zyjiaocheng/576/0068969cc7664bec96e2dd5b7703df73.jpg)
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
内容总结
以上是互联网集市为您收集整理的Mysql中对表字段的增删改查_MySQL全部内容,希望文章能够帮你解决Mysql中对表字段的增删改查_MySQL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。