如何修改mysql数据库表结构


本文摘自PHP中文网,作者coldplay.xixi,侵删。

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

本教程操作环境:windows7系统、mysql 8.0.22版、thinkpad t480电脑。

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

修改mysql数据库表结构的方法:

1、查看表结构

1

2

3

4

5

6

7

8

9

10

11

12

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、添加列

1

2

3

mysql> alter table student add column birthday datetime;

Query OK, 0 rows affected (2.06 sec)

Records: 0  Duplicates: 0  Warnings: 0

3、删除列

1

2

3

mysql> alter table student drop column birthday;

Query OK, 0 rows affected (0.80 sec)

Records: 0  Duplicates: 0  Warnings: 0

4、修改列

1

2

3

4

5

6

7

8

9

--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数据库表结构的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

mysql中什么是临时表

mysql router的安装部署

mysql两大存储引擎innodb与myisam的区别

mysql 怎样创建桌面快捷

mysql有什么作用?

mysql是一种什么型数据库管理系统

mysql中varchar最大长度有多大

mysql如何获取当前时间

mysql的事务,隔离级别和锁用法实例分析

mysql增加外键有哪些方法

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

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

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

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

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...