修改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、查看表结构
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、添加列
安装、修复、更新或打包一个基于 Python 和 PyMySQL 实现的 Windows `mysql` 命令。适用于用户希望在 PowerShell/CMD 中输入 `mysql` 时重定向到 Python 实现、需要交互式输入 MySQL 连接信息、需要同步到当前用户本地 bin 目录,或需要将该能力封装成可公开复用的 Codex skill。
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
相关免费学习推荐:编程视频










