Home > Database > Mysql Tutorial > body text

How to add fields in mysql

藏色散人
Release: 2022-01-12 15:36:53
Original
63892 people have browsed it

Mysql method of adding fields: [create table id_name(id int, name varchar(20));], which means adding id and name fields.

How to add fields in mysql

mysql adds two fields:

(recommended tutorial: mysql video tutorial)

mysql> create table id_name(id int,name varchar(20));
Query OK, 0 rows affected (0.13 sec)

mysql> alter table id_name add age int,add address varchar(11);
Query OK, 0 rows affected (0.13 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc id_name;

+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id      | int(11)     | YES  |     | NULL    |       |
| name    | varchar(20) | YES  |     | NULL    |       |
| age     | int(11)     | YES  |     | NULL    |       |
| address | varchar(11) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Copy after login

mysqlAdd a field:

alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL; //增加一个字段,默认为空
alter table user add COLUMN new2 VARCHAR(20) NOT NULL;  //增加一个字段,默认不能为空
Copy after login

The above is the detailed content of How to add fields in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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