MySQL Data modification

Source: Internet
Author: User

1 Adding a single column

A ALTER TABLE list name add the parameter name ( such as age) to add the content ( such as 21); "At the bottom of all columns"

b ALTER table list name add the parameter name ( such as age) to add the content ( such as Tirst); "The newly added column is at the front"

C ALTER table list name add the parameter name (for example, age ) to add to the column specified by Afier (for example) ; " The newly added column is located below the column you specified.

2 adding multiple columns

altertableList nameADDthe name of the parameter to add(such as age) content(as);the name of the parameter to add(such as name)  content(such as Sulinlin);wait"At the bottom of all columns"

3 Deleting a single column

alteertable List name DROP the name of the parameter to delete ( e.g. age ) ;

4 Deleting multiple columns

ALTER table name drop the parameter name ( such as name ) to delete , and also the parameter name ( such as age ) to delete; wait

5 You can also delete edges to add

6 Adding a PRIMARY KEY constraint ( only one )

ALTER TABLE list name PRIMARY REY ( the primary KEY constraint name to be added );( is actually the name of the parameter name)

7 Adding a unique constraint ( can have multiple )

ALTER TABLE list name add unique ( the unique constraint name to add );( is actually the parameter name, such as age )

8 adding foreign KEY constraints

altertable List name ADD FOREIGN Key ( foreign key parameter ) refrences List name (name of the parameter);

9 Adding a DEFAULT constraint

Alter ABLE table name alter parameter SET default value ;

10 Deleting a DEFAULT constraint

ALTER TABLE name alter parameter DROP DEFAULT;

11 See which parameters in the list are constrained and indexed

First step SHOW INDEXES from list name;

The second step SHOW INDEXES from list name \g;

12 Deleting a PRIMARY KEY constraint

ALTER table name DROP primapy KEY;

13 Deleting a UNIQUE constraint

ALTER table name DROP INDEX parameter;

14 Deleting a FOREIGN KEY constraint

ALTER table name DROP FOREIGN key foreign KEY constraint name;

15 Viewing FOREIGN KEY constraint names

SHOW CREATE table table name;

16 Deleting an index

ALTER TABCE table name DROP Index has an indexed parameter name;




MySQL Data modification

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.