This article uses an example to describe how to add, delete, and modify columns in a MySQL database. Share with you for your reference, the details are as follows: Create a new table user_info: CREATE TABLE user_info( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, username CHAR(20) NOT NULL DEFAULT '', gender TINYINT UNSIGNED NOT NULL DEFAULT 0, weight TINYINT UNSIGNED NOT NULL DEFAULT 0 )ENGINE=MyISAM DEFAULT CHARSET=utf8; The new column is the last column of the table by default. Syntax: alter table table name add column name column type column attribute alter table user_info add height tinyint unsigned not null default 0; Deleting a column Syntax: alter table table name drop column name alter table user_info drop height; Add a column and put it after the specified column Syntax: alter table table name add column name type attribute [default value] after specify column name alter table user_info add height tinyint not null default 0 after username; Modify the specified column name Syntax: alter table table name change old column name new column name type attribute default value alter table user_info change height shengao smallint not null default 0; modify Modify the column, but cannot modify the column name Syntax: alter table table name modify column name type attribute default value alter table user_info modify shengao tinyint not null default 0; Readers who are interested in more MySQL-related content can check out the following topics: "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills". I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Implementation process of nginx high availability cluster
>>: Real-time refresh of long connection on Vue+WebSocket page
Since the default Linux kernel parameters are bas...
Table of contents Demand background Thought Analy...
1. golang:latest base image mkdir gotest touch ma...
After studying React for a while, I want to put i...
Newbie, record it yourself 1. Install supervisor....
Import: Due to project requirements, we will enca...
1. Today, when I was making a page, I encountered ...
Since the problem occurred rather suddenly and th...
First, setInterval is encapsulated as a Hook 👇 im...
Editor's note: This article is contributed by...
First, let’s look at the GIF operation: Case 1: S...
This article example shares the specific code of ...
This article example shares the specific code of ...
Table of contents Nesting Parent-child component ...
Table of contents Preface 1. Trigger Overview 2. ...