Home>Article>Database> How to modify the field in mysql to be non-null

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

青灯夜游
青灯夜游 Original
2022-01-04 14:58:13 15663browse

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;

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!

Statement:
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