Home > Article > Daily Programming > How to express non-null in mysql
There are two ways to express non-null in MySQL: using NOT NULL constraints to prohibit fields from being null. Use the DEFAULT value to specify a default value for fields that are not explicitly specified.
How to express non-null in MySQL
In MySQL, non-null is usually expressed as NULL values are not allowed. There are two main ways to represent non-null:
1. NOT NULL constraint
NOT NULL
constraint mandatory fields are not allowed NULL value. CREATE TABLE my_table (id INT NOT NULL);
2. DEFAULT value
DEFAULT
value to specify a default value for the field, even if the value is not explicitly specified. CREATE TABLE my_table (name VARCHAR(255) DEFAULT 'John Doe');
Detailed description:
NOT NULL constraint:
DEFAULT value:
Note:
INT
and VARCHAR
) allow NULL values. NOT NULL
constraint or DEFAULT value. NOT NULL
constraints. The above is the detailed content of How to express non-null in mysql. For more information, please follow other related articles on the PHP Chinese website!