MySQL first Knowledge (iii) modifying table structure

Source: Internet
Author: User

MySQL Modify table structure


The following table names test5 only one field hobby operation
Modify Table Name
ALTER TABLE TEST5 rename Newtest;

Change the name of a field at the same time
Statement structure ALTER TABLE name change field name new field name [First|after field name]
First|after can be written or not, the position of the change field is in the foreground or behind a field.
ALTER TABLE newtest change hobby hob char (20);

Just modify the field
Statement Authority ALTER TABLE name modify field name [First|after field name]
Can still change the position of the modified field
ALTER TABLE newtest Modify HOB char (100);

Append field
Statement structure ALTER TABLE name add field name [First|after field name]
ALTER TABLE newtest add tid tinyint first;

Delete a field
Statement structure ALTER TABLE table name drop field name
ALTER TABLE newtest drop TID;

Add primary Key
Statement structure ALTER TABLE name add primary key (field name);
ALTER TABLE Newtest add primary key (ID);
Note that if you have a primary key in the table, you cannot add a primary key and the field contents of the primary key cannot be duplicated.

Delete primary key
Statement structure ALTER TABLE name drop PRIMARY key;
There's no need to emphasize which field is a primary key because one table

MySQL first Knowledge (iii) modifying table structure

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.