Home > Database > Mysql Tutorial > body text

How to modify the mysql database table structure

coldplay.xixi
Release: 2023-01-04 09:37:31
Original
2436 people have browsed it

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】.

How to modify the mysql database table structure

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 structure

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)
Copy after login

2. Add columns

mysql> alter table student add column birthday datetime;
Query OK, 0 rows affected (2.06 sec)
Records: 0  Duplicates: 0  Warnings: 0
Copy after login

3. Delete columns

mysql> alter table student drop column birthday;
Query OK, 0 rows affected (0.80 sec)
Records: 0  Duplicates: 0  Warnings: 0
Copy after login

4. Modify the column

--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
Copy after login

Related free learning recommendations:

Programming Video

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!