Oracle 5.0 Reference Manual page 51

Table of Contents

Advertisement

possible scenario. In this case, it is better to "do the best you can" and then continue as if nothing
happened.
In MySQL 5.0.2 and up, you can select stricter treatment of input values by using the
STRICT_TRANS_TABLES
SET sql_mode = 'STRICT_TRANS_TABLES';
SET sql_mode = 'STRICT_ALL_TABLES';
STRICT_TRANS_TABLES
some extent for nontransactional engines. It works like this:
• For transactional storage engines, bad data values occurring anywhere in a statement cause the
statement to abort and roll back.
• For nontransactional storage engines, a statement aborts if the error occurs in the first row to
be inserted or updated. (When the error occurs in the first row, the statement can be aborted
to leave the table unchanged, just as for a transactional table.) Errors in rows after the first do
not abort the statement, because the table has already been changed by the first row. Instead,
bad data values are adjusted and result in warnings rather than errors. In other words, with
STRICT_TRANS_TABLES
if that can be done without changing the table. But once the table has been changed, further errors
result in adjustments and warnings.
For even stricter checking, enable
STRICT_TRANS_TABLES
the statement even for bad data in rows following the first row. This means that if an error occurs
partway through a multiple-row insert or update for a nontransactional table, a partial update results.
Earlier rows are inserted or updated, but those from the point of the error on are not. To avoid this for
nontransactional tables, either use single-row statements or else use
if conversion warnings rather than errors are acceptable. To avoid problems in the first place, do not
use MySQL to check column content. It is safest (and often faster) to let the application ensure that it
passes only legal values to the database.
With either of the strict mode options, you can cause errors to be treated as warnings by using
or
IGNORE
UPDATE IGNORE
1.8.6.4.
and
ENUM
SET
and
ENUM
SET
of values. See
before MySQL 5.0.2,
columns always have a default value. If you specify no default value, then it is
ENUM
columns that can have NULL, otherwise it is the first enumeration value in the column definition.
• If you insert an incorrect value into an
IGNORE, it is set to the reserved enumeration value of 0, which is displayed as an empty string in
string context.
• If you insert an incorrect value into a
column can contain the values 'a', 'b', and 'c', an attempt to assign
value of 'a,b'.
As of MySQL 5.0.2, you can configure the server to use strict SQL mode. See
SQL
Modes". With strict mode enabled, the definition of a
on values entered into the column. An error occurs for values that do not satisfy these conditions:
• An
value must be one of those listed in the column definition, or the internal numeric equivalent
ENUM
thereof. The value cannot be the error value (that is, 0 or the empty string). For a column defined as
ENUM('a','b','c'), values such as '', 'd', or
How MySQL Deals with Constraints
[539]
or
STRICT_ALL_TABLES
[539]
enables strict mode for transactional storage engines, and also to
[539], a wrong value causes MySQL to roll back all updates done so far,
STRICT_ALL_TABLES
[539]
except that for nontransactional storage engines, errors abort
rather than
Constraints
columns provide an efficient way to define columns that can contain only a given set
Section 11.1.6.4, "The
ENUM
and
columns do not provide true constraints on entry of invalid data:
ENUM
SET
[539]
[539]. This is the same as
or
without IGNORE.
INSERT
UPDATE
Type", and
Section 11.1.6.5, "The
column or if you force a value into an
ENUM
column, the incorrect value is ignored. For example, if the
SET
ENUM
are illegal and are rejected.
'ax'
31
SQL modes:
STRICT_TRANS_TABLES
Type". However,
SET
NULL
ENUM
'a,x,b,y'
Section 5.1.7, "Server
or
column does act as a constraint
SET
[539]
INSERT
for
column with
results in a

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents