百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> 怎样修改mysql数据库表构造
分享文章到:

怎样修改mysql数据库表构造

发布时间:01/01 来源:未知 浏览: 关键词:

修改mysql数据库表构造的办法:1、查看表构造;2、增加列;3、删除列,代码为【mysql> alter table student drop column birthday】;4、修改列,代码为【mysql> alter table】。

本教程操纵环境:windows7系统、mysql8.0.22版,该办法适用于所有品牌电脑。

相关免费学习引荐:mysql数据库(视频)

修改mysql数据库表构造的办法:

1、查看表构造

mysql> show create table student;
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                                                          |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| student | CREATE TABLE `student` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `NAME` varchar(20) NOT NULL,
  `AGE` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.09 sec)

2、增加列

mysql> alter table student add column birthday datetime;
Query OK, 0 rows affected (2.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

3、删除列

mysql> alter table student drop column birthday;
Query OK, 0 rows affected (0.80 sec)
Records: 0  Duplicates: 0  Warnings: 0

4、修改列

--1.修改列的类型
mysql> alter table student modify age int not null;
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
--2.修改列的名称
mysql> alter table student change column name sname varchar(20);
Query OK, 0 rows affected (1.31 sec)
Records: 0  Duplicates: 0  Warnings: 0

相关免费学习引荐:编程视频

以上就是怎样修改mysql数据库表构造的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板