Home  >  Article  >  Database  >  Command to delete columns in mysql

Command to delete columns in mysql

下次还敢
下次还敢Original
2024-04-29 03:54:13410browse

The command to delete a column in MySQL is ALTER TABLE. The syntax is ALTER TABLE table_name DROP COLUMN column_name. It can be used to delete non-primary key columns. The data in the column before deletion must be empty or NULL. After deletion, the data in the column will be Lost, for InnoDB tables, the table will be rebuilt after deleting the column.

Command to delete columns in mysql

Command to delete columns in MySQL

ALTER TABLE command is used to delete columns in MySQL tables Delete columns in . It looks like this:

<code class="sql">ALTER TABLE table_name DROP COLUMN column_name;</code>

Syntax:

  • table_name: The name of the table from which to delete the column.
  • column_name: The name of the column to be deleted.

Example:

To delete the "email" column from the table named "customers", use the following command:

<code class="sql">ALTER TABLE customers DROP COLUMN email;</code>

Note:

  • Only non-primary key columns can be deleted.
  • The deleted column must be empty or contain a value that can be NULL.
  • When a column is deleted, all data in the column will be lost.
  • For InnoDB tables, after deleting a column, the table will be rebuilt, which may take a while.

The above is the detailed content of Command to delete columns in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn