To add columns to an existing table in MySQL, you can use the ALTER TABLE
statement. Here’s the basic syntax:
ALTER TABLE table_name
ADD column_name column_definition;
Replace table_name
with the name of the table to which you want to add the column, column_name
with the name of the new column, and column_definition
with the data type and any other attributes for the new column.
For example, if you want to add a new column named email
of type VARCHAR(100) to a table named users
, you would use:
ALTER TABLE users
ADD email VARCHAR(100);
You can also specify additional attributes like NOT NULL
, DEFAULT
, etc., as needed for your column definition.