MySQL NOT null details to ask
For example, a SQL DDL statement like this:
Password char (+) NOT NULL default "",//MD5
Since the definition of NOT NULL, then the user forced the need to add a password, then a default value is not a bit redundant? And my length is 32 bits, the default value is NULL,
When the feeling has not NULL, the default value, there is no need to exist, even if there is, his Value property is not the property of the field of the Convention ah? Solving!
Share to:
------Solution--------------------
Contrary
When not NULL, press the default input if you don't type.
In other words you set NOT NULL is best (MUST) set default
------Solution--------------------
Irrelevant!
Password is just a name, and it doesn't make any sense for the database.
The purpose of the NOT NULL default "" is to: if it is not assigned a value, the default value is an empty string. That is, the item can be inserted by default
If only not NULL, then the item must have a value when inserted, otherwise an error
If the contract password must have a value, then the definition should be
Password char (+) NOT NULL,
Instead of
Password char (+) NOT NULL default "",
------Solution--------------------
It's customary to give a default.
------Solution--------------------
References:
irrelevant!
Password is just a name, and it doesn't make any sense for the database.
The purpose of the NOT NULL default "" is to: if it is not assigned a value, the default value is an empty string. That is, the item can be inserted by default
If only not NULL, then the item must have a value when inserted, otherwise an error
If the contract password must have a value, then the definition should be
Password char (+) NOT NULL,
Instead of
Password char (+) NOT NULL default "",
The positive solution, your needs are:
Password char (+) NOT NULL
If you add the default "", the database will store a string of length 0 "" If you do not pass the value.
Null! = ""