Data types in the database

Source: Internet
Author: User

One. Digital type
Integral type
TINYINT 1 bytes
SMALLINT 2 bytes Short
Mediumint 3 bytes
(common) int 4 byte int
BIGINT 8 bytes Long
Floating point Type
Float single precision 4 byte float
**double 8 bytes DOUBLE
*decimal no loss of precision

    • Decimal when using floating-point data, like money, commodity unit price and so on, encountered decimals are generally used double,decimal length is also 8 bytes
    • Floating-point data in the operation often results in the loss of precision, in the need for frequent calculations, such as financial systems, then you can use decimal, the underlying use is a string to save, the calculation is 0 precision missing.

What is the difference between DOUBLE and DECIMAL?
The double type has a missing precision when it is being operated on.
DECIMAL is the solution to the problem of lack of precision. (The underlying uses a string to hold the number)

When you simply want to represent a decimal attribute, double is used.
Decimals that require frequent participation in the operation, using Decimal.
Two. String type
Note: String types are wrapped using single quotes.
Short String type
Char/varchar (maximum length 255 bytes)
Question: What is the difference between char and varchar?
Char fixed-length string. VarChar represents a variable-length string.
Also specify a length of 10. When storing ABC
char = "ABC"
varchar = ' abc '
Conclusion: The most used in the development of varchar. Char is used only in enumerations that represent fixed lengths. For example: gender (expressed in 01,02)
Long string type (stream type)
*text/clob saves text (character streams)--used when the content to be saved exceeds 255 bytes. Writer characters in Java
BLOB Save bytes (byte stream)-no stream bytes in Java in development

Character Large Object
Binary Large Object

Text: Only character data can be stored.
BLOB: can store character and multimedia information (picture sound image)

    • The output text of the byte stream is fine, but it is impossible to take a stream of characters to output the sound.
      Long string types are not commonly used.
    • Personal privacy, voice, image, computer was lost, to repair the computer is also OK.

//------------------------------------------------------------------------------------------------------------- -----
Three. Date and Time type
Date only recorded on 2015-01-14
Time is only recorded 11:36:25
Year Only records years 2015
Datatime record date and record time 2015-01-14 11:36:25
**timestamp Ibid. 2015-01-14 11:36:25

Question: What is the difference between datatime and timestamp?
The data for these two types of records is identical.
The difference is that when inserting the Datatime type, the default value of the type is null if no value is passed.
If the timestamp type is inserted without a value, the default value for that type is the current time;

Data types in the database

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: 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.