Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Im trying to get eeror about invalid data for a query but it seems mysql accept strings as tiney in queries and set 0 instead of returning any error.
So how can I restrict it to just accept integers.
Thanks in advance.
这是依赖于SQL 模式的。
在严格模式下,您必须收到“数据被截断”(插入的值从数字字符开始)或“不正确的整数值”(第一个符号不是数字)错误消息,并且不得插入任何数据。
如果禁用严格模式,则生成警告而不是错误,并将值转换为数字(从第一个非数字开始的所有符号都被截断,然后将值转换为数字,如果它是空字符串,则分配零)。
首先执行数据类型检查(如果需要,还可以进行转换),甚至在 INSERT 触发器之前。
DEMO