Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A detailed list of common data types in SQL

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The data type describes the CHARACTER (n) character / string. Fixed length n. VARCHAR (n) or

CHARACTER VARYING (n) character / string. Variable length. Maximum length n. BINARY (n) binary string. Fixed length n. BOOLEAN stores TRUE or FALSE values VARBINARY (n) or

BINARY VARYING (n) binary string. Variable length. Maximum length n. INTEGER (p) integer value (no decimal point). Precision p. SMALLINT integer value (no decimal point). Precision 5.

The range of stored data is from-2 to the 15th power of 2 (- 32768) to the 15th power of 2 (32767), occupying 2 bytes of storage space. INTEGER integer value (no decimal point). The precision is 10.

The range of stored data is-2 to the 31st power of 2 to the 31st power of 2, occupying 4 bytes of storage space. BIGINT integer value (no decimal point). The accuracy is 19. DECIMAL (pforce s) accurate value, precision p, decimal point after the number of s. For example, decimal (5, 2) is a number with 3 digits before the decimal point and 2 digits after the decimal point. NUMERIC (pforce s) accurate value, precision p, decimal point after the number of s. (same as DECIMAL) FLOAT (p) approximate value, Mantissa precision p. A floating-point number that uses an exponential counting method with a base of 10. The size parameter of this type consists of a single number that specifies the minimum precision. REAL approximate value, Mantissa precision 7. FLOAT approximate value, Mantissa precision 16. DOUBLE PRECISION approximate value, Mantissa precision 16. DATE stores the values of year, month, and day. TIME stores the values of hours, minutes, and seconds. TIMESTAMP stores the values of year, month, day, hour, minute, and second. INTERVAL consists of integer fields that represent a period of time, depending on the type of interval. A fixed-length ordered collection of ARRAY elements an unordered collection of variable length MULTISET elements XML stores XML data

Among them, the red is the data type commonly used in building tables.

There are some differences in the names of data types among different database platforms, and in SQL Server and MY SQL (or other platforms) numeric types also have a tinyint type (ranging from 0 to 255).

Attention should be paid to the selection of different data types according to the actual situation.

First, defining that the length of data is too long will result in a waste of storage space.

For example:

For the "name" field: Chinese names are generally not too long and can be defined as char (10). Char (10) can store 5 Chinese characters. While the need to consider ethnic minorities or other names are very long (such as foreigners? ), you need to change it to char (20) or longer

Second, inaccurate selection of types may have an impact on subsequent operations.

For example:

For the "age" field: theoretically, "age" can be defined as char and tinyint. When there is no need to calculate the age, it is no problem to define it as char, but in many cases, we need to calculate, sort, and compare the age, and it is more convenient to choose tinyint. And the range of life expectancy of normal earthlings is no more than 150 small int and int is too large, resulting in a waste of space.

For the phone number field: the varchar type is recommended. If the telephone number is divided into fixed telephone number and mobile phone number, the length is different. Varchar is more flexible, variable in length, and has less storage space than char.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report