怎么修改mysql数据库表结构

37次阅读
没有评论

共计 1810 个字符,预计需要花费 5 分钟才能阅读完成。

自动写代码机器人,免费开通

这篇文章主要介绍了怎么修改 mysql 数据库表结构,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让丸趣 TV 小编带着大家一起了解一下。

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

修改 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

感谢你能够认真阅读完这篇文章,希望丸趣 TV 小编分享怎么修改 mysql 数据库表结构内容对大家有帮助,同时也希望大家多多支持丸趣 TV,关注丸趣 TV 行业资讯频道,遇到问题就找丸趣 TV,详细的解决方法等着你来学习!

向 AI 问一下细节

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-18发表,共计1810字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)