Home > Database > Mysql Tutorial > body text

How to modify the field in mysql to be non-null

青灯夜游
Release: 2022-01-04 14:58:13
Original
15780 people have browsed it

In mysql, you can use the "ALTER TABLE" statement and the "NOT NULL" keyword to modify the field to be non-null. When modifying the table, a non-null constraint will be set for the field. The syntax is "ALTER TABLE table name CHANGE COLUMN Field name field name data type NOT NULL;".

How to modify the field in mysql to be non-null

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

mysql Modify the field to be non-null

If you forget to set the non-null constraint for the field when creating the table, you can also modify the table. Addition of non-null constraints.

The syntax format for setting non-empty constraints when modifying the table is as follows:

ALTER TABLE <数据表名>
CHANGE COLUMN <字段名>
<字段名> <数据类型> NOT NULL;
Copy after login

Example

Modify the data table tb_dept4, and the specified location cannot be empty

How to modify the field in mysql to be non-null

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to modify the field in mysql to be non-null. 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