To delete a column from a MySQL table, you can use the ALTER TABLE
statement with the DROP COLUMN
clause.
To delete a column from a MySQL table, follow these steps:
mysql
utility. You can use the mysql
utility to connect to the MySQL server as the root user or another user with the appropriate privileges. For example:mysql -u root -p
Enter the password for the user account when prompted.
USE
command to select the database:mysql> USE database_name;
Replace database_name
with the name of the database that contains the table you want to modify.
ALTER TABLE
statement with the DROP COLUMN
clause to delete the column from the table. You can use the following syntax to delete a column from a MySQL table:mysql> ALTER TABLE table_name DROP COLUMN column_name;
Replace table_name
with the name of the table, and column_name
with the name of the column you want to delete.
Confirm the changes. MySQL will prompt you to confirm the changes. Type y
and press Enter to delete the column from the table.
Disconnect from the MySQL server. Once you have finished deleting the column from the table, you can disconnect from the MySQL server by typing exit
at the MySQL prompt:
mysql> exit
After deleting the column from the table, the column will no longer be present in the table and any data stored in the column will be lost. Be careful when deleting columns from a MySQL table, as this operation cannot be undone.