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 ); ";
Multiple columns can be deleted from the MySQL table using a single ALTER statement by separating the DROP keyword and column name list with a comma.
Use ALTER TABLE DROP COLUMN statement to delete one or more columns of a table using T-SQL. Syntax: ALTER TABLE [schema_name.] table_name DROP column column_name1, column_name2,...
Multiple columns can be dropped with a single query by simply comma separating a list of DROP COLUMN statments. To drop both the "foo" and "bar" columns from the "test" table do this: ALTER TABLE test DROP COLUMN foo, DROP COLUMN bar; As many additional columns can be added to the list as required.
First, you define the table name from which you wish to remove or delete the column. Second, you write the column name you want to delete in the DROP clause. A user can also drop multiple columns simultaneously from a table. You can do this by listing out the column names that you want to drop, separated by a comma.
ALTER TABLE `tablename` DROP `column1`, DROP `column2`, DROP `column3`;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With