mysql如何处理无效的数据值

mysql如何处理无效的数据值


mysql对插入的数据有时候不是我们意料中的,这不是bug,是mysql固有的设计。


3.3 How MySQL Handles Invalid Data Values

Historically, the dominant principle for data handling in MySQL has been,“Garbage in, garbage out.” In other words,

 MySQL attempts to store any data value you give it, but if you don’t verify the value first before storing it, you may not like what

 you get back out.
However, as of MySQL 5.0.2, several SQL modes are available that enable you to reject bad values and cause an error to

 occur instead.The following discussion first discusses how MySQL handles improper data by default, and then covers the

 changes that occur when you enable the various SQL modes that affect data handling.
By default, MySQL handles out-of-range or otherwise improper values as follows:

  •  For numeric or TIME columns, values that are outside the legal range are clipped to the nearest endpoint of the range and the resulting value is stored.
  •  For string columns other than ENUM or SET, strings that are too long are truncated to fit the maximum length of the column.
  • Assignments to an ENUM or SET column depend on the values that are listed as legal in the column definition. If you assign to an ENUM column a value that is not listed as an enumeration member, the error member is assigned instead (that is, the empty string that corresponds to the zero-valued member). If you assign to a SET column a value containing substrings that are not listed as set members, those strings drop out and the column is assigned a value consisting of the remaining members.
  • For date or time columns, illegal values are converted to the appropriate “zero” value for the type (see Table 3.15).
These conversions are reported as warnings for statements such as INSERT, REPLACE, UPDATE, LOAD DATA, and ALTER TABLE.You can use SHOW WARNINGS after executing one of those statements to see the warning messages.


   具体SQL modes详看https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html 


 读书笔记:

MySQL (4th Edition)

作者Paul DuBois 
出版社: Addison-Wesley Professional
出版年: 2008-09-08
页数: 1224
定价: USD 49.99
装帧: Paperback
ISBN: 9780672329388



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dreamer who

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值