MySQL Tutorial
The ALTER TABLE
statement in MySQL is used to modify an existing table by adding, deleting, renaming, or changing columns, constraints, and indexes.
To add a new column to an existing table:
address
column with a VARCHAR(255)
data type.To remove a column from a table:
address
column.To rename a column:
name
to full_name
.To modify the data type of a column:
age
column to SMALLINT
.To rename a table:
students
table to learners
.student_id
as the primary key.Warning
Ensure the column is not AUTO_INCREMENT before dropping
student_id
in enrollments
to students
.To drop a foreign key constraint, find its name first:
Then, drop the foreign key:
name
for faster searches.