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 PHP7 came out, as a fan of the latest versi...
#mysql -uroot -p Enter password mysql> show fu...
1. DNS server concept Communication on the Intern...
<body> <div id="root"> <...
Table of contents Environmental conditions Errors...
Business scenario: The visitor's visit status...
1. Natural layout <br />The layout without a...
Table of contents MySQL basic common commands 1. ...
Source: http://www.ruoyi.vip/ import Vue from ...
1. What is a two-column layout? There are two typ...
This article uses an example to describe how to u...
Node.js solves the problem of Chinese garbled cha...
Dockerfile is a file used to build a docker image...
Portainer is a lightweight docker environment man...
1. Virtual Machine Preparation 1. Create a new vi...