MySQL add column, move column

Source: Internet
Author: User

ALTER TABLETestADD COLUMNIdINTUNSIGNED not NULLAuto_incrementPRIMARY KEYfirst, adding a column to a table is a common operation, and when MySQL increments the column, you can specify that the column's location should be two keywords for the specified location. Note that MySQL does not use the before when adding columns to the specified position, the first column can use the after with first, not column one. Syntax:ALTER TABLEtable_nameADD [COLUMN] col_nameColumn_definition[First | After Col_name]Example:DROP TABLE IF EXISTS' test ';CREATE TABLE' Test ' (' a 'int( One) not NULL, ' B 'varchar( $) not NULL) ENGINE=InnoDBDEFAULTCHARSET=UTF8; Add a column C after the test table a column:ALTER TABLETestADD COLUMNCINT  not NULLafter a adds the field ID in the first column of the test table:ALTER TABLETestADD COLUMNIdINTUNSIGNED not NULLAuto_incrementPRIMARY KEYFirst, move the ID column to column one:ALTER TABLE' table_name ' change ' ID ' ID 'int  not NULLAuto_increment first;

MySQL add column, move column

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.