Get the App
SLTechnology News&Howtos  ›  Database  › 

The implementation method of adding, deleting and modifying columns in MySQL Database

Shulou Source: shulou.com Published: 2022-06-01 04:39:27 11月20日 Update

This paper gives an example to describe the implementation method of adding, deleting and modifying columns in 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 defaults to the last column of the table

Syntax: alter table table name add column name column type column attribute

Alter table user_info add height tinyint unsigned not null default 0

Delete column

Syntax: alter table table name drop column name

Alter table user_info drop height

Add a column, after the specified column

Syntax: alter table table name add column name type attribute [default] after specifies the 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 property default

Alter table user_info change height shengao smallint not null default 0

Modify modifies columns, but cannot modify column names

Syntax: alter table table name modify column name type attribute default

Alter table user_info modify shengao tinyint not null default 0

More readers who are interested in MySQL-related content can check out this site's special topics: "A Summary of MySQL Common functions", "A Collection of MySQL Log Operation skills", "MySQL transaction Operation skills Summary", "MySQL stored procedure skills Collection" and "MySQL Database Lock related skills Summary"

It is hoped that what is described in this article will be helpful to everyone's MySQL database design.

Tags: Syntax attributes techniques types data databases encyclopedia methods topics transactions interests content functions instances common use logs more readers procedures references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi Apple macOS Shulou Tech Info