How to: MySQL Delete Column

www.‮ttual‬uri.com
How to: MySQL Delete Column

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:

  1. Connect to the MySQL server using the 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.

  1. Select the database that contains the table you want to modify. You can use the 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.

  1. Use the 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.

  1. Confirm the changes. MySQL will prompt you to confirm the changes. Type y and press Enter to delete the column from the table.

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

Created Time:2017-10-29 22:08:42  Author:lautturi