Summary of modifying fields in the Mysql database

Source: Internet
Author: User
Mysql database Field modification method summary 1 Add Table field altertablestudentaddsexvarchar (2) notnull; types. modify the field type of a table and specify the field name of the specified empty or non-empty altertable name modify

Mysql database Field modification method summary 1 add table field alter table student add sex varchar (2) not null; alter table student add id int unsigned not null auto_increment primary key 2. modify the field type of a table and the field name modify, which is specified as null or not.

Summary of modifying fields in the Mysql database
1. Add Table Fields

Alter table student add sex varchar (2) not null;


Alter table student add id int unsigned not null auto_increment primary key


2. Modify the field type of a table and specify it as null or non-empty.

Alter table name modify Field Name field type [whether to allow non-null not null/null];


Eg: alter table student modify name varchar (20) null


3. Modify the field name of a table and specify it as null or not

Alter table name change field Original Name field New Name field type [whether to allow non-null not null/null]


Eg: alter table student change sex xingbie varchar (3) not null;


4. to delete a field, run the following command:

Alter table Name drop field name;


Eg: alter table student drop xingbie;

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.