Alterations
Explore how to modify existing MySQL tables using the ALTER TABLE statement. Learn to rename columns, change data types, add or remove columns, and manage column positions. Understand when altering tables can be costly and how to combine multiple changes into one statement for efficiency.
We'll cover the following...
Alterations
MySQL allows us to change our mind about the entities we create and alter them. We can rename tables, add, remove, or rename columns, change type of an existing column, etc.
Example Syntax
ALTER TABLE table
CHANGE oldColumnName newColumnName <datatype> <restrictions>;
Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/17lesson.sh and wait for the MySQL prompt to start-up.
-
Let’s say we want to rename the column FirstName to First_Name for the Actors table. We can do so as follows:
ALTER TABLE Actors CHANGE FirstName First_Name varchar(120);