[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
NOT NULL
and DEFAULT
values To be able to support easy handling of non-transactional tables all columns in MySQL have default values.
If you insert an "incorrect" value in a column, such as a NULL
in a
NOT NULL
column or a too-large numerical value in a numerical
column, MySQL sets the column to the "best possible value"
instead of producing an error. For numerical values, this is either 0, the
smallest possible value or the largest possible value. For strings, this is
either the empty string or the longest possible string that can be in
the column.
This means that if you try to store NULL
into a column that
doesn't take NULL
values, MySQL Server instead stores 0 or "
(the empty string). This last behavior can, for single row
inserts, be changed with the -DDONT_USE_DEFAULT_FIELDS
compile
option.) See section configure
options.
This causes INSERT
statements to generate an error unless you
explicitly specify values for all columns that require a non-NULL
value.
The reason for the preceding rules is that we can't check these conditions until the query has begun executing. We can't just roll back if we encounter a problem after updating a few rows, because the table type may not support rollback. The option of terminating the statement is not that good; in this case, the update would be "half done," which is probably the worst possible scenario. In this case it's better to "do the best you can" and then continue as if nothing happened.
This means that you should generally not use MySQL to check column content. Instead, the application should ensure that is passes only legal values to MySQL.
In MySQL 5.0, we plan to improve this by providing warnings when automatic column conversions occur, plus an option to let you roll back statements that attempt to perform a disallowed column value assignment, as long as the statement uses only transactional tables.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |