MySQL Modify data structure

Source: Internet
Author: User

Need to use, tidy up a bit. (change to lowercase for easy viewing)

View Table creation statement: show CREATE TABLE table_name;Change table name: ALTER TABLE old_table rename [to] New_table;//renameModify table data type: ALTER TABLE table_name MODIFY COLUMN_NAME attributes//modifyModify field name: ALTER TABLE table_name change old_name new_name new_attributs;//changeadd field: ALTER TABLE table_name add new_name new_attributes;//adde.g. ALTER TABLE books add title char (a) Not NULL primary key First;//first//At the frontALTER TABLE new_name add author char (+) not NULL after Name;//after//placed after the name fieldDelete field: ALTER TABLE table_name DROP COLUMN_NAME;//DROPModify field Location: ALTER TABLE table_name modify file_name attr after column_name;Modify the data table engine: ALTER TABLE table_name Engine=new_engine;//engineView data table engine: Show table status from database_name where name= ' table_name ';//status//The above also looks at other basic information of the tableDelete foreign KEY constraint for table: ALTER TABLE table_name drop foreing key key_name; Add index: ALTER TABLE table_name ADD index index_name (column name);ALTER TABLE table_name add unique (column list name);ALTER TABLE TABLE_NAME ADD PRIMARY key (column list names);//index_name Optional, default to first columnCREATE INDEX INDEX_NAME on table_name (column list names);Create unique index index_name on table_name (column list names);//create Unable to create primary key indexDelete index: ALTER TABLE table_name DROP INDEX index_name;ALTER TABLE table_name drop PRIMARY key;DROP INDEX index_name on table_name;View index: Show index from Talbe_name; To Modify the database encoding:database: ALTER database db_name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci; table: ALTER table table_name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

MySQL Modify data 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.