Last Updated: 28 May, 2023
In MySQL, We can add one or more new columns in the existing table with the help of ALTER TABLE statement.
The syntax and example are as follows:
Syntax:
ALTER TABLE table_name ADD new_column_name column_definition [FIRST | AFTER column_name];
Example:
ALTER TABLE student ADD marks int NOT NULL;
Add multiple new columns
The syntax and example for adding multiple columns are as follows:
Syntax:
ALTER TABLE table_name ADD new_column_name1 column_definition[FIRST | AFTER column_name], ADD new_column_name2 column_definition [FIRST | AFTER column_name], ... ADD new_column_nameN column_definition [FIRST | AFTER column_name];
Example:
ALTER TABLE student ADD dob date, ADD marks int, ADD home_city VARCHAR(100);
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com