Use ALTER to modify the table structure in MYSQL

Source: Internet
Author: User
Tags mysql command line

What should I do if I want to implement MYSQL to modify the table structure? You can use ALTER to modify the table structure in MYSQL. The following describes the detailed method for your reference.

Mysql alter table structure usage

Project instance:

Alter table TestResult ADD xinlinDoc longblob;

Alter table TestResult ADD xinlinDocName varchar (50 );

Other instances:

Create table t1 (a INTEGER, B CHAR (10); // The created TABLE t1 starts.

Alter table t1 RENAME t2; // RENAME the TABLE from t1 to t2

Alter table t2 MODIFY a tinyint not null, CHANGE B c CHAR (20); // to CHANGE column a from INTEGER to tinyint not null (same name), and CHANGE column B, change from CHAR (10) To CHAR (20), rename it, and change from B to c:

Alter table t2 ADD d TIMESTAMP; // ADD a new TIMESTAMP column named d

Alter table t2 add index (d), add primary key (a); // ADD an INDEX on column d and set column a as the PRIMARY KEY

Alter table t2 drop column c; // delete COLUMN c

Alter table t2 ADD c int unsigned not null AUTO_INCREMENT, add index (c); // ADD a new AUTO_INCREMENT integer column named c. Note that we have indexed c, because the AUTO_INCREMENT column must be indexed, and we declare c as not null, because the indexed Column cannot be NULL. When you add an AUTO_INCREMENT column, the column values are automatically entered with sequential numbers.

The preceding describes how to use ALTER to modify the table structure in MYSQL.

Add new users through MySQL Command Line

MySQL permission table Introduction

Instances that grant MySQL user permissions

Eight things to pay attention to in MySql Indexes

How to view MySQL Indexes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.