如何修改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 oracle 哪个好学?

mysql设计规范与原则

远程mysql数据库无法访问设置

mysql和sql是什么?mysql和sql之间的区别有哪些

mysql中的中文显示为问号怎么办

mysql如何输出汉字信息

外键ddl在oracle运行正常,在mysql报异常以及解决方案

centos7 mysql 5.6 多主一从 解决方案与详细配置

mysql中关于char和varchar的区别

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


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

数据库系统概念 第6版

机械工业出版社

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



打赏

取消

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

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

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

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

评论

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