Modify table field type modifyCategoryDetailed explanationBasic syntaxalter table table name modify field name varchar(20);##ExampleExample description Let’s execute it and see the result:
alter table user modify username varchar(20);
Change the type of username in the user table to varchar(20)
mysql> alter table user modify username varchar(20);
CategoryDetailed explanation##Basic syntaxalter table table name add column field name type; alter table user add column age int(3);Add a field as age, type is integer, length is 3
Control the order of fields when adding fieldsWe just learned to add fields. If you carefully experiment and find that every time it is added at the end, how to add it at the first one or after the pointing field? CategoryDetailed explanationBasic syntaxALTER TABLE table name ADD field name field type AFTER field name;ExampleALTER TABLE user ADD email VARCHAR(60) AFTER createip;Example descriptionIn the user table, add a field as email after createip, the type is varchar, the length is 60
Table field renameCategoryDetailed explanationBasic syntaxalter table table name change field original name field new name field type;Examplealter table user change email em varchar(60);Example descriptionIn the user table, name the email field in the field em
Detailed example:
mysql> alter table user change email em varchar(60); Query OK, 0 rows affected (0.38 sec) Records: 0 Duplicates: 0 Warnings: 0
Modify the order of table fieldsIn the previous field addition and modification statements (add/change/modify), you can add one at the end Optional first|after. We have already learned how to adjust the order when adding table fields. Let's now take a look at how another change or modify can adjust the order. Let’s do a small experiment with first. Use modify to adjust the order
mysql> alter table user modify em varchar(60) first;
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning