tags:

views:

137

answers:

1
mysql> CREATE TABLE foo ( f ENUM('a', '123') );

mysql> insert into foo(f) value(3);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from foo;
+------+
| f    |
+------+
|      |
+------+

How to make it produce a failure when inserting a value out of range?

+4  A: 

From 10.4.4. The ENUM Type

If strict SQL mode is enabled, attempts to insert invalid ENUM values result in an error.

astander
How to enable strict mode?
To check our current SQL mode at the mysql prompt type `SELECT @@global.sql_mode;`. To change the current SQL mode to strict type type `SET @@global.sql_mode = “STRICT_ALL_TABLES”;`
Daniel Vassallo
Tried,not working,empty values are still inserted
what is your warning? i copied your code, and I get an error message: "#1265 - Data truncated for column 'f' at row 1". The record is NOT inserted! My global sql mode is STRICT_TRANS_TABLES.
Marga Keuvelaar