MySQL NOT null details please

Source: Internet
Author: User
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! = ""
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.