MySQL Drop Multiple Columns

PhpMysql

Php Problem Overview


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
		);
	";

Php Solutions


Solution 1 - Php

ALTER TABLE `tablename`
DROP `column1`,
DROP `column2`,
DROP `column3`;

Solution 2 - Php

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCory NickersonView Question on Stackoverflow
Solution 1 - PhpvoidView Answer on Stackoverflow
Solution 2 - PhpMANISH ZOPEView Answer on Stackoverflow