gpt4 book ai didi

MySQL插入无效日期

转载 作者:行者123 更新时间:2023-11-29 05:46:24 25 4
gpt4 key购买 nike

再说一次,这个qn是mysql认证指南书上的练习qns...

问题

Here's the structure of a table typetest with three columns (number, string, and dates). As- sume the server is running in MySQL's “forgiving” SQL mode.mysql> DESCRIBE typetest;+--------+---------------------+------+-----+---------+-------+| Field | Type  | Null | Key | Default | Extra |+--------+---------------------+------+-----+---------+-------+| number | tinyint(3) unsigned | YES    |   | NULL  |   |+--------+---------------------+------+-----+---------+-------+You perform the following INSERT operation on table typetest:INSERT INTO typetest VALUES (1000,'yoodoo','999-12-31');What data values will actually be stored in the table? Provide a short explanation. 

回答

+--------+--------+------------+| number | string | dates   |+--------+--------+------------+|   255 | yoodo | 0000-00-00 |+--------+--------+------------+The inserted number 1000 is too big to fit in the TINYINT UNSIGNED column, so the highest pos- sible value (255) is inserted. 'yoodoo' is too long for a CHAR(5) column and is thus truncated to five  characters.  '999-12-31' is  a  date  that  is  earlier  than  the  earliest  possible  DATE value ('1000-01-01'). This is interpreted as an invalid date, so the “zero” date is stored.

当我尝试将“999-12-31”插入日期时,我得到了 0999-12-31。我在认证指南的某些地方读到 mysql 可能能够插入 1000-01-01 到 9999-12-31 范围之外的日期。但是在考试中我要回答什么?

最佳答案

您可以阅读 Constraints on Invalid Data部分。不幸的是,它不能直接回答您的问题。它说“如果日期完全错误(服务器无法存储它),特殊的“零”日期值'0000-00-00'将存储在列中。”,我会说存储 0999 不是'不可能...

关于MySQL插入无效日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1326159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com