Home > Database > Mysql Tutorial > How to add columns (fields) to a table in mysql?

How to add columns (fields) to a table in mysql?

青灯夜游
Release: 2020-09-28 10:12:11
Original
29447 people have browsed it

Mysql method to add columns to a table: 1. Use "ALTER TABLE table name ADD new field name data type [constraints];" to add columns at the end; 2. Use "ALTER TABLE table name ADD new Field Name Data Type [Constraint] FIRST;" Add columns at the beginning.

How to add columns (fields) to a table in mysql?

(Recommended tutorial: mysql video tutorial)

MySQL data table is composed of rows and columns, usually The "columns" of the table are called fields, and the "rows" of the table are called records. As your business changes, you may need to add new fields to existing tables.

MySQL allows adding fields at the beginning, middle and end.

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: