日期:2014-05-16 浏览次数:20753 次
mysql> select @@sql_mode; +----------------------------+ | @@sql_mode | +----------------------------+ | STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +----------------------------+
mysql> show variables like 'sql_mode%'\G; *************************** 1. row *************************** Variable_name: sql_mode Value: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
mysql> set @@sql_mode=ANSI; Query OK, 0 rows affected (0.00 sec) mysql> create table test(name varchar(4), pass varchar(4)); Query OK, 0 rows affected (0.03 sec) mysql> insert into test values('aaaaa','aaaaa'),('bbbb','bbbb'); Query OK, 2 rows affected, 2 warnings (0.02 sec) Records: 2 Duplicates: 0 Warnings: 2 mysql> show warnings; +---------+------+-------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------+ | Warning | 1265 | Data truncated for column 'name' at row 1 | | Warning | 1265 | Data truncated for column 'pass' at row 1 | +---------+------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> select * from test; +------+------+ | name | pass | +------+------+ | aaaa | aaaa | | bbbb | bbbb | +------+------+ 2 rows in set (0.00 sec)
mysql> set @@sql_mode=STRICT_TRANS_TABLES; Query OK, 0 rows affected (0.00 sec) mysql> create table test(name varchar(4), pass varchar(4)); Query OK, 0 rows affected (0.02 sec) mysql> insert into test values('aaaaa','aaaaa'),('bbbb','bbbb'); ERROR 1406 (22001): Data too long for column 'name' at row 1 mysql> show errors; +-------+------+------------------------------------------+ | Level | Code | Message | +-------+------+------------------------------------------+ | Error | 1406 | Data too long for column 'name' at row 1 | +-------+------+------------------------------------------+ 1 row in set (0.00 sec) mysql> select * from test; Empty set (0.00 sec)
mysql> set @@sql_mode=TRADITIONAL; Query OK, 0 rows affected (0.00 sec) mysql> create table test(name varchar(4), pass varchar(4)); Query OK, 0 rows affected (0.02 sec) mysql> insert into test values('aaaaa','aaaaa'),('bbbb','bbbb'); ERROR 1406 (22001): Data too long for column 'name' at row 1 mysql> show errors; +-------+------+------------------------------------------+ | Level | Code | Message | +-------+------+------------------------------------------+ | Error | 1406 | Data too long for column 'name' at row 1 | +-------+------+------------------------------------------+ 1 row in set (0.00 sec) mysql> select * from test; Empty set (0.00 sec)
mysql> select @@sql_mode\G; *************************** 1. row *************************** @@sql_mode: STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,E RROR_FOR_