Home > Database > Mysql Tutorial > body text

How to add fields to the database table

青灯夜游
Release: 2023-02-17 17:21:17
Original
49866 people have browsed it

Methods to add fields in the table: 1. Use the "ALTER TABLE table name ADD new field name data type;" statement to add fields at the end; 2. Use "ALTER TABLE table name ADD new field name data type FIRST ;" statement adds fields at the beginning; 3. Use the "ALTER TABLE table name ADD new field name data type [constraints] AFTER existing field name;" statement to add fields in the middle.

How to add fields to the database table

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

How to add fields in the table in Mysql database

1. Add fields at the end

A complete field includes field name, data type and constraints. The syntax format for adding fields in MySQL is as follows:

ALTER TABLE <表名> ADD <新字段名><数据类型>[约束条件];
Copy after login

The syntax format is explained as follows: