Home > Database > Mysql Tutorial > Command to delete columns in mysql

Command to delete columns in mysql

下次还敢
Release: 2024-04-29 03:54:13
Original
476 people have browsed it

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template