MySQL Basics five--data modification

Source: Internet
Author: User

1. Add a single column

ALTER table tab_red (table name) ADD age (column name) INT (column type) constraint {first| After Dname (after the Dname column)};

ALTER TABLE tab_red ADD age INT not NULL DEFAULT 10;

2. Add multiple columns

ALTER table tab_red (table name) ADD (dname varchar (), age int unsigned);

Adding multiple columns Cannot set the position of a column, and cannot be placed between the first column and a column. Only default in the last.

3. Delete a single column

ALTER table tab_red (table name) DROP dname (column name);

4. Delete multiple columns

ALTER table tab_red (table name) DROP Dname,drop age;

5. Deleting columns while adding a new column

ALTER TABLE tab_red DROP dname,add age INT;

6. Add a PRIMARY key

Alter TABLE tab_red ALTER DNAME set default Literal/drop default;

7. Delete a PRIMARY KEY constraint

ALTER TABLE tab_red DROP PRIMARY KEY;

MySQL Basics five--data modification

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.