featured computer 850

MySQL Rename a Table or Column

Share page:

Summary

As of MySQL 5.0, renaming a table is trivial with the “rename table” function. Renaming a column was a little cryptic, even looking at the documentation. Here are a couple of concrete examples.

To rename a table from “lu_wind_direction” to “lu_direction”:

mysql> rename table lu_wind_direction to lu_direction;

To rename a column called “wind_speed” to “speed” in the table named “spacetime”:

mysql> alter table spacetime change wind_speed speed tinyint(3) unsigned;

So, when renaming a column, it’s just the original name first, then after the new name, you need to include the column specifications and constraints.

Similar Posts