Description of the actual operation syntax for modifying a MySQL table

Source: Internet
Author: User

The following articles mainly describe MySQL table modification, that is, adding or deleting columns and creating or canceling indexes. We all know that after MySQL creates a related database, if a table is created and some fields are added, how can I add fields in the future?

A: Use alter table )!

Alter table Syntax:

 
 
  1. ALTER [IGNORE] TABLE tbl_name  
  2. alter_specification [, alter_specification] ...  
  3. alter_specification:  
  4. ADD [COLUMN] column_definition [FIRST | AFTER col_name ]  
  5. | ADD [COLUMN] (column_definition,...)  
  6. | ADD INDEX [index_name] [index_type] (index_col_name,...)  
  7. | ADD [CONSTRAINT [symbol]]  
  8. PRIMARY KEY [index_type] (index_col_name,...)  
  9. | ADD [CONSTRAINT [symbol]]  
  10. UNIQUE [index_name] [index_type] (index_col_name,...)  
  11. | ADD [FULLTEXT|SPATIAL] [index_name] (index_col_name,...)  
  12. | ADD [CONSTRAINT [symbol]]  
  13. FOREIGN KEY [index_name] (index_col_name,...)  
  14. [reference_definition]  
  15. | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}  
  16. | CHANGE [COLUMN] old_col_name column_definition  
  17. [FIRST|AFTER col_name]  
  18. | MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]  
  19. | DROP [COLUMN] col_name  
  20. | DROP PRIMARY KEY  
  21. | DROP INDEX index_name  
  22. | DROP FOREIGN KEY fk_symbol  
  23. | DISABLE KEYS  
  24. | ENABLE KEYS  
  25. | RENAME [TO] new_tbl_name  
  26. | ORDER BY col_name  
  27. | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]  
  28. | [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]  
  29. | DISCARD TABLESPACE | IMPORT TABLESPACE | table_options  
  30. | partition_options  
  31. | ADD PARTITION partition_definition  
  32. | DROP PARTITION partition_names  
  33. | COALESCE PARTITION number  
  34. | REORGANIZE PARTITION partition_names INTO (partition_definitions)  
  35. | ANALYZE PARTITION partition_names  
  36. | CHECK PARTITION partition_names  
  37. | OPTIMIZE PARTITION partition_names  
  38. | REBUILD PARTITION partition_names  
  39. | REPAIR PARTITION pa   

The above content is an introduction to MySQL table modification. I hope you will have some gains.

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.