Get the App
SLTechnology News&Howtos  ›  Database  › 

How to modify the structure of mysql database table

Shulou Source: shulou.com Published: 2022-06-01 01:42:58 09月13日 Update

This article mainly introduces how to modify the mysql database table structure, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

Methods to modify the mysql database table structure: 1, view the table structure; 2, add columns; 3, delete columns, code is [mysql > alter table student drop column birthday]; 4, modify columns, code is [mysql > alter table].

How to modify the structure of mysql database tables:

1. View the 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)

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

3. Delete columns

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

4. Modify the column

-1. Modify the column type mysql > alter table student modify age int not null;Query OK, 0 rows affected (0.09 sec) Records: 0 Duplicates: 0 Warnings: 0-- 2. Modify the name of the column mysql > alter table student change column name sname varchar (20); Query OK, 0 rows affected (1.31 sec) Records: 0 Duplicates: 0 Warnings: 0 Thank you for reading this article carefully. I hope it will be helpful for everyone to share how to modify the structure of the mysql database table. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Tags: Structure data database method article code value content at the same time name friend type ribbon industry information information channel question channel reference learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Huawei NVidia OPPO Reno