Detailed MySQL data type of the correct use of the number type

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags .mall class data data type database systems design digital e-commerce sites

Either in the pitiful free database space or large e-commerce sites, reasonable design table structure, make full use of space is very necessary. This requires that we have a full understanding of the commonly used MySQL data types for database systems. Now I will write down my little experience to share with you.

The numeric type of the MySQL data type

According to my classification of digital types are divided into three categories: integer, decimal and digital categories.

My so-called "digital class" refers to DECIMAL and NUMERIC, which are the same type. It strictly speaking is not a type of numbers, because they are actually stored as a string of numbers; each of his values ​​(including the decimal point) accounts for a byte of storage space, so this type of space-consuming comparison Big. But one of its outstanding advantages is that the decimal places are fixed and will not be "distorted" in the calculation, so it is more suitable for fields such as "price" and "amount" that require less precision but require very high accuracy.

Fractional, that is, the types of floating-point, depending on the accuracy, there are two FLOAT and DOUBLE. Their advantage is accuracy. FLOAT can represent a decimal with a very small absolute value as small as about 1.17E-38 (0.000 ... 0117, with 37 zeros after the decimal point), and DOUBLE can represent an absolute value as small as about 2.22E-308 (0.000 ... 0222, 307 zeros after the decimal point).

FLOAT type and DOUBLE type of storage space is 4 bytes and 8 bytes. If you need to use the decimal field, the accuracy is not high, of course, with FLOAT. But to be honest, the data for our "civil" data are so high as to be required? Both types have not been used up to now - I have not encountered any examples that are suitable for using them.

Most used, the most cost-effective, is an integer type. From TINYINT, which occupies only one byte of storage, to BIGINT, which occupies eight bytes, choosing a type that is "good enough" and takes up the least amount of storage space should be considered when designing your database. TINYINT, SMALLINT, MEDIUMINT, INT, and BIGINT occupy 1 byte, 2 bytes, 3 bytes, 4 bytes and 8 bytes, respectively. For unsigned integers, the largest integers represented by these types are 255, 25535, 16777215, 4294967295 and 18446744073709551615.

If used to save the user's age (for example, the age of the database is not desirable to save), with TINYINT enough; Ninetowns "aspect", the skill value, with SMALLINT enough; if you want to use For a certainly not more than 16000000 rows table AUTO_INCREMENT IDENTIFY field, of course MEDINTINT without INT, imagine, save a byte per line, 16000000 lines can save 10 trillion!

Related Article

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.