Overview
When you design a library table, you often encounter fields for saving time values, such as create_date,begin_time,login_time, and so on. For these types of fields, there is an interesting phenomenon when setting data types, where some people use the date type, while others use the Char (8)/char (14) type. Generally speaking, beginners, students in school, and even teachers generally belong to the former, they are a distinct feature of the theory of the database is very good, but the general lack of practical project development experience; the latter are generally those who have a certain project experience. At first glance, these time value fields, with the date type should be reasonable and justified, why a certain project experience people must be such "qiantouming", so "maverick"?
This is a typical white cat black cat problem, the theoretical things are very shiny, but sometimes in practice is not brilliant, and some "heterodoxy" things are more convenient and easy to use. This article will analyze why the char type Time field is more popular in practice, using a specific example of different development processes. Given the space limit, we only compare the date type with the time value fields of type char (8) and the analysis of the date type and char (14) type, and I believe we can all do that.
1. Examples of comparisons
We have designed a concrete example that compares the dates of the char type and date type and uses an Oracle database, which is briefly described.
Suppose you have a t_user table with a expire_date (expiration date) field that requires the date data for the year, month, and day to be recorded, and two implementations for the Expire_date field:
Figure 1 T_user Table
The left T_user (1) uses char (8) to save the date value in the YYYYMMDD format, such as 20070606,20070501, and the Right T_user (2) uses the date data type, which we call the data table on the left as the Char type Date scheme. The design on the right is the date type day scheme.
The data in the table is of course not born, so let's assume that it's submitted from a Web form, save to the table, of course, there are queries, statistics and other operations, we will use these common data operations analysis of these two different scenarios, through such analysis, which is inferior, I believe we can make a good judgment.
2, add records from the form comparison
Struts+spring+hibernate is a popular framework for the current Web project, in which hibernate needs to be t_ User generates a User.java Po,char type date scheme user.expiredate is of type string, whereas the user.expiredate of the date type day scheme is the java.sql.Date type, as shown in Figure 2:
Fig. 22 The corresponding User.java PO of the scheme respectively