Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Drop Multiple Columns

Tags:

php

mysql

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         );     "; 
like image 342
Cory Nickerson Avatar asked Apr 04 '13 23:04

Cory Nickerson


People also ask

How can I delete multiple columns in a table in MySQL?

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.

How do you delete multiple columns in SQL?

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,...

How do I DROP multiple columns in a database?

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.

How do you use DROP columns?

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.


1 Answers

ALTER TABLE `tablename` DROP `column1`, DROP `column2`, DROP `column3`; 
like image 86
void Avatar answered Sep 29 '22 01:09

void