Home > Database > Mysql Tutorial > body text

How to add a column to the original table in sql

醉折花枝作酒筹
Release: 2023-01-07 11:45:55
Original
24416 people have browsed it

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

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

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!

Related labels:
sql
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template