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
Preface InnoDB stores data in tablespaces. In the...
Comments and messages were originally a great way...
Test environment: C:\>systeminfo | findstr /c:...
Preface: When we use Vue, we often use and write ...
1Basic steps of echarts Four Steps 1 Find the DOM...
Many people say that IE6 does not support PNG tra...
There is a table user, and the fields are id, nic...
1. Add the ul tag in the body first <!-- Unord...
1. Display effect: 2, html structure <div clas...
This article uses examples to explain the princip...
Table of contents Preface environment Install Cre...
Table of contents Introduction Download and insta...
Character set error always exists locale: Cannot ...
MySQL Performance Optimization MySQL performance ...
The full name of SSH is Secure SHell. By using SS...