• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

mysql 搞代码 4年前 (2022-01-09) 15次浏览 已收录 0个评论

gaodaima.com

Mysql中对表字段的增删改查

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

本文来源gaodai.ma#com搞##代!^码7网

排序

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)

gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Mysql中对表字段的增删改查_MySQL
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址