Home  >  Article  >  Database  >  Commonly used basic operation syntax of mysql (2)~~Add, delete and modify operations on tables [command line mode]

Commonly used basic operation syntax of mysql (2)~~Add, delete and modify operations on tables [command line mode]

黄舟
黄舟Original
2017-03-03 13:55:421335browse

1. Modify the table name: alert table oldtablename rename newtablename; or alert table oldtablename rename to newtablename;


[graphical interface If you use it too much, alter will always be typed into alert]

2. Add a field column at the end of the table: alter table tablename add attribute name attribute type;


3. Add fields in the first column of the table: alter table tablename add attribute name attribute type first;


4. Specify fields in the table Add fields later: alter table tablename add attribute name attribute type after attribute name;


##5. Delete fields: alter table tablename drop attribute name;



6. Modify the data type of the field: alter table tablename modify attribute name new data type;


7. Modify the field name: alter table tablename change old attribute name new attribute name old data type;



Note: If the data type is not the old one but replaced with a new data type, the field name and data type will be changed at the same time.

8. Modify the position of the field: alter table tablename modify attribute name 1 data type first or after attribute name 2;


## The above is mysql Commonly used basic operation syntax (2)~~Add, delete, and modify operations on tables [command line mode]. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn