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;".
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
[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!