Whether the field type of the date stored in the database should be either varchar or datetime

Source: Internet
Author: User

To change the data type of the storage time in the database to varchar (), it is best to make these times automatically generated in the database (an unformatted input may also result in an output error), because the storage type is varchar (), so the obtained value is considered a string. Convert the time strings in the database directly (at which point the conversion functions are able to recognize the time functions in the database), and the client's time format no longer affects the conversion process.

However, the type of storage time in a database can be problematic if it is a character type:

The time in the database is only used to display, find, then the impact is not big, but if the time field to do some algorithms such as computing weeks, DateDiff, DateAdd, and so on, it is troublesome, especially the large data query conversion type is the impact of efficiency

Summarize

Should the field type of the date stored in the database be either varchar or datetime? Both methods have advantages, and datetime can borrow the arithmetic functions in the SQL function library to increase the efficiency of time on various operations, while the varchar type can show advantages in character coding. You might consider choosing a varchar type if the stored time does not require a large amount of computation in the future, and conversely, choosing a datetime type.

Whether the field type of the date stored in the database should be either varchar or datetime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.