Delete two columns through the ALTER TABLE statement: 1. Determine the column name to be deleted; 2. Write the statement: ALTER TABLE table_name DROP COLUMN column_name1, column_name2; 3. Execute the statement.
How to delete two columns using SQL code
In SQL you can useALTER TABLE
statement deletes columns in the table. To delete two columns, you can perform the following steps:
1. Determine the columns you want to delete
First, determine the names of the two columns you want to delete from the table .
2. Write anALTER TABLE
statement
Write anALTER TABLE
statement, specifying the table name and the column to be deleted name. The statement syntax is as follows:
ALTER TABLE table_name DROP COLUMN column_name1, column_name2;
3. Execute the statement
Execute this statement using your preferred SQL client (such as MySQL Workbench, PostgreSQL pgAdmin, etc.).
Example
Suppose you have a table namedemployees
with two columnsfirst_name
andlast_name
. To delete these columns, you can execute the following statement:
ALTER TABLE employees DROP COLUMN first_name, last_name;
After executing this statement, tableemployees
will no longer containfirst_name
andlast_name
List.
The above is the detailed content of How to delete the contents of two columns using code in sql. For more information, please follow other related articles on the PHP Chinese website!