MySql防止错误的枚举查询/ stransaction

时间:2016-01-13 02:38:40

标签: mysql enums

如果我有gender ENUM('m', 'f')

的枚举

,输入类似于:

UPDATE person
SET gender = 'Z'
WHERE person_id = 1;

结果:

Query OK, 0 rows affected, 1 warning (0.06 sec)
Rows matched: 1  Changed: 0  Warnings: 1

+-----------+---------+--------+--------+------------+------------------+--------+-------+---------+-------------+
| person_id | fname   | lname  | gender | birth_date | street           | city   | state | country | postal_code |
+-----------+---------+--------+--------+------------+------------------+--------+-------+---------+-------------+
|         1 | William | Turner |        | 1972-05-27 | 1225 Tremont St. | Boston | MA    | USA     | 02138       |
+-----------+---------+--------+--------+------------+------------------+--------+-------+---------+-------------+

警告是:

+---------+------+---------------------------------------------+
| Level   | Code | Message                                     |
+---------+------+---------------------------------------------+
| Warning | 1265 | Data truncated for column 'gender' at row 1 |
+---------+------+---------------------------------------------+

如果提供了错误的值,如何防止查询完全执行?

0 个答案:

没有答案