Why is the mysql field set to notnull? Now, let's explain to you. First, we create a table with the asd field being null and the qwe field being notnull. No Default CREATETABLE 'tb' ('id' INT (10) UNSIGNEDNOTNULLAUTO_INCREMENT, 'asd 'varchar (45) NULL, 'Qi' VARCHAR (45) NO
Why should I set the mysql field to not null? Now, the master will explain to you. First, we CREATE a TABLE. The asd field is null, And the qwe field is not null. No Default create table 'tb' ('id' INT (10) unsigned not null AUTO_INCREMENT, 'asd 'VARCHAR (45) NULL, 'Qi' VARCHAR (45) NO
Why should I set the mysql fieldnot null
?
Now, I want to explain this to you.
First, create a table.asd
The field isnull
,qwe
The field isnot null
, No Default Value
CREATE TABLE `tb` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,`asd` VARCHAR(45) NULL,`qwe` VARCHAR(45) NOT NULL,PRIMARY KEY (`idtb`))
Then
insert tb(asd) values('123123123');insert tb(qwe) values('123123123');
Now let's look at this table. Please input the image description. We can see that if the qwe field of not null is not set, it is an empty string. If the asd field is not set, it is a null value. can be imagined. So why should we set not null? Because MYSQL is not php, NULL is not equal to an empty string. For example, if we query the select * from tb where qwe = ''where qwe is empty, enter the image description, but select * from tb where asd ='' indicates all but when we develop the WEB, sure enough, some insert records specify NULL strings, and some insert records do NOT specify a value. If the field is not null, it is displayed: Enter the image description, enter the image description. Therefore, if you want to set not null, no NULL will appear.