2009-08-25 69 views
1

再次,这是QN从MySQL认证指导书的做法QNS ...MySQL的插入无效日期

问题

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. 

ANSWER

+--------+--------+------------+ 
| 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。但是在考试中我回答了什么?

回答

0

考试和现实生活是不同的东西。如果在书中另写一个,很难证明你的意见。但我会回答说,我测试了我自己的。

2

您可以阅读Constraints on Invalid Data部分。不幸的是,它不能直接回答你的问题。它说:“如果日期完全错误(在服务器存储能力之外),那么特殊的”零“日期值'0000-00-00'将被存储在列中。”,我想说存储0999 isn'牛逼不可能的...

0

Mysql的日期范围:1000年1月1日至9999-12-31(REF)

在这里,您试图插入 '999-12-31'。由于这个日期不在上述范围内,因此默认值为0