MySQL Drop Multiple Columns
I'm trying to drop multiple columns, but having some trouble. The syntax below works when I do ALTER TABLE
and ADD
with multiple values in the brackets ()
but it doesn't work with DROP COLUMN
. Am I using the wrong syntax?
$table3 = "
ALTER TABLE $table3_name
DROP COLUMN (
user_firstname,
user_lastname,
user_address,
user_address2,
user_city,
user_state,
user_zip,
user_phone
);
";
Solution 1:
ALTER TABLE `tablename`
DROP `column1`,
DROP `column2`,
DROP `column3`;
Solution 2:
To drop multiple columns actual syntax is
alter table tablename drop column col1, drop column col2 , drop column col3 ....
So for every column you need to specify "drop column" in Mysql 5.0.45. This is same as that of above answer. Just adding one point here. Alter table wont free up the actual space on the disk. So run optimize table on after running optimize table.