Methods to modify the table structure of mysql database: 1. View the table structure; 2. Add columns; 3. Delete columns, the code is [mysql> alter table student drop column birthday]; 4. Modify columns, the code is 【mysql> alter table】.
The operating environment of this tutorial: windows7 system, mysql version 8.0.22, thinkpad t480 computer.
Related free learning recommendations: mysql database(Video)
##Modify Mysql database table structure method:
1. View table structuremysql> 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)
mysql> alter table student add column birthday datetime; Query OK, 0 rows affected (2.06 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table student drop column birthday; Query OK, 0 rows affected (0.80 sec) Records: 0 Duplicates: 0 Warnings: 0
--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
Related free learning recommendations:
The above is the detailed content of How to modify the mysql database table structure. For more information, please follow other related articles on the PHP Chinese website!