Home  >  Article  >  Database  >  statement to delete column in sql

statement to delete column in sql

下次还敢
下次还敢Original
2024-05-02 01:33:14536browse

In SQL, the syntax for using the ALTER TABLE statement to delete a table column is: ALTER TABLE table_name DROP COLUMN column_name. This statement permanently deletes all data in the specified column. If the column is part of a foreign key, unique constraint, or primary key, the associated constraints must also be deleted.

statement to delete column in sql

SQL statement to delete a column

In SQL, you can use ALTER TABLE statement to delete a column from the table. The syntax is as follows:

<code>ALTER TABLE table_name DROP COLUMN column_name;</code>

Among them:

  • table_name is the name of the table where the column is to be deleted.
  • column_name is the name of the column to be deleted.

Example

Suppose we have a table named customers which contains the following columns:

<code>id | name | email | phone</code>

To delete the phone column, you can use the following statement:

<code>ALTER TABLE customers DROP COLUMN phone;</code>

Note:

  • After deleting a column, all data in the column All will be permanently deleted.
  • If the column being deleted is a foreign key, the foreign key constraint associated with the column must also be deleted.
  • If the column being dropped is part of a unique constraint or primary key, these constraints must also be dropped.

The above is the detailed content of statement to delete column in sql. 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
Previous article:How to use minus in sqlNext article:How to use minus in sql