Editing a column in a MySQL database—whether you’re changing its name, data type, or constraints—is done using the ALTER TABLE
statement. Here’s a complete tutorial with step-by-step instructions and helpful video guides to walk you through it.
🛠️ How to Edit a Column in MySQL
🔧 1. Modify a Column’s Data Type or Constraints
Use the MODIFY COLUMN
clause:
ALTER TABLE table_name
MODIFY COLUMN column_name new_data_type;
📘 Example:
ALTER TABLE users
MODIFY COLUMN age INT NOT NULL;
📺 How to alter and modify a column in MySQL | Alter a Table in … clearly demonstrates how to change column types and apply constraints using ALTER TABLE
.
📖 Learn more from W3Schools: MySQL ALTER TABLE and MySQL Tutorial: ALTER TABLE.
✏️ 2. Rename a Column
Use the CHANGE COLUMN
clause:
ALTER TABLE table_name
CHANGE COLUMN old_name new_name data_type;
📘 Example:
ALTER TABLE users
CHANGE COLUMN fullname name VARCHAR(100);
📺 Change or rename column name in SQL | Mysql tutorial walks through renaming a column using MySQL Workbench and the CHANGE
keyword.
📺 MySQL Tutorial for Beginners 20 – MySQL ALTER TABLE … includes a section on renaming columns and using ALTER TABLE
effectively.
➕ 3. Add a New Column
ALTER TABLE table_name
ADD COLUMN new_column_name data_type;
📺 MySQL tutorial 14 – Altering tables shows how to add, remove, and modify columns in under 7 minutes.
❌ 4. Delete a Column
ALTER TABLE table_name
DROP COLUMN column_name;
📺 MySQL Database Tutorial – 31 – ALTER / DROP / RENAME … covers dropping columns and renaming tables with practical examples.
🔄 5. Update Data in a Column
If you want to change the actual data inside a column:
UPDATE table_name
SET column_name = new_value
WHERE condition;
📺 MySQL tutorial 11 – Update a row demonstrates how to update rows using UPDATE
and WHERE
clauses.