Home  >  Article  >  Database  >  How to modify the field in mysql to allow it to be empty

How to modify the field in mysql to allow it to be empty

WBOY
WBOYOriginal
2022-05-19 16:04:5520820browse

In mysql, you can use the alter table statement with modify to modify the fields that are allowed to be empty. Modify is used to modify the data length, data type and field constraints of the fields in the table. The syntax is "alter table table name modify Field name field type (length) null;".

How to modify the field in mysql to allow it to be empty

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

How does mysql modify the field to allow it to be empty

Problem

MySQL modifies the field to allow it to be empty

Solution

alter table topic modify state int(4) null;

Syntax Summary

alter table表名 modify字段名字段类型(长度) null;

Extended knowledge:

The role of ALTER TABLE

ALTER TABLE command is used to add, delete or change existing There are columns in the data table.

You can also use the ALTER TABLE command to add or delete constraints on existing data tables.

modify is used to modify the data length, data type and field constraints of the fields in the table.

Mysql method to modify the field to null:

1. SQL syntax

Create a new query and use the statement setting: update p_order set finish_time=null where id='XXXX '

2. Set

in navicat for mysql. Double-click to open the p_order table, find the record that needs to be modified through time sorting, and right-click on the finish_time of the record (no need to delete the data) ), there will be Set to Null (English: Set to Null) after right-clicking, and the result has been set to Null value.

Recommended learning: mysql video tutorial

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