Home  >  Article  >  Database  >  How to add a column to the original table in sql

How to add a column to the original table in sql

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-27 15:50:1524348browse

In mysql, you can use the "ALTER TABLE" statement to add a column to the original table. The syntax format is "ALTER TABLE data table name ADD field name field type"; this statement is used to add a column to an existing table. Add, modify, or delete columns.

How to add a column to the original table in sql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

ALTER TABLE table_name ADD column_name datatype

(The table name cannot be table, this is a reserved word. After ADD, the added column name and data type are added)

ALTER TABLE statement Used to add, modify or delete columns in an existing table.

To drop a column from a table, use the following syntax:

ALTER TABLE table_name DROP COLUMN column_name

Note: Some database systems do not allow this way of dropping a column in a database table (DROP COLUMN column_name).

To change the data type of a column in the table, please use the following syntax:

ALTER TABLE table_name ALTER COLUMN column_name datatype

Related recommendations: "mysql tutorial"

The above is the detailed content of How to add a column to the original table 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