How can you change a field name in MySQL?
You can change the name of a MySQL table column using the ALTER TABLE statement. Here are the specific steps:
- Use the ALTER TABLE statement to change the name of a table’s column.
- Modify the field name and data type of a table.
- The table name refers to the name of the table where the field name is to be changed, the old field name is the original name that needs to be changed, the new field name is the new name for the field, and the data type is an optional field data type that maintains the field type unchanged.
- By executing the above ALTER TABLE statement, you can change the field name.
Here is an example:
Assume there is a table called “students” with a column named “old_name”. Now we need to change the name of this column to “new_name”.
ALTER TABLE students CHANGE old_name new_name 数据类型;
After running the above statement, the field name “old_name” in the students table will be changed to “new_name”.