Modify Table Structure in MySQL -- add and delete Fields

Source: Internet
Author: User
Tags mysql index

Modifying the table structure in MySQL includes many functions. The following describes how to modify the table structure in MySQL to add and delete fields. If you are interested in modifying the table structure in MySQL, take a look.

Modify Table Structure in MySQL -- add fields:

Alter table 'user _ movement_log'
Add column GatewayId int not null default 0 AFTER 'regionid' (AFTER which field is added)

Modify Table Structure in MySQL -- delete fields:

Alter table 'user _ movement_log 'drop column Gatewayid

Adjust the field order:

Alter table 'user _ movement_log 'CHANGE 'gatewayid' int not null default 0 AFTER RegionID

// Primary key

Alter table tabelname add new_field_id int (5) unsigned default 0 not null auto_increment, add primary key (new_field_id );

// Add a new column

Alter table t2 add d timestamp;
Alter table infos add ex tinyint not null default '0 ′;

// Delete a column

Alter table t2 drop column c;

// Rename a column

Alter table t1 change a B integer;

// Change the column type

Alter table t1 change B bigint not null;
Alter table infos change list tinyint not null default '0 ′;

// Rename the table

Alter table t1 rename t2;

10 common MySQL command lines

Use the MySQL command line to change the password

Cancel MySQL user permissions

Commands that grant MySQL user permissions

Mysql index Comparison Analysis

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.