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

What are the data types of mysql

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

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you what data types mysql has, Xiaobian thinks it is quite practical, so share it with you to learn, I hope you can gain something after reading this article, don't say much, follow Xiaobian to have a look.

tinyint , smallint ,mediumint,int,bigint Range

type

bytes

minimum value

maximum value

(signed/unsigned)

(signed/unsigned)

TINYINT

1

-128

127

0

255

SMALLINT

2

-32768

32767

0

65535

MEDIUMINT

3

-8388608

8388607

0

16777215

INT

4

-2147483648

2147483647

0

4294967295

BIGINT

8

-9223372036854775808

9223372036854775807

0

18446744073709551615

1. Difference between char and varchar

char (13) fixed length, such as 'www.jb51.net' storage space required 12 characters

varchar(13) variable length such as 'www.jb51.net' requires storage space of 13 characters,

Usually stored in a fixed-length string, it is recommended to use char, such as mobile phone number, etc.

If yes, variable e.g. name, url, etc. varchar

1, CHAR length is fixed, VARCHAR length varies with the size of the content. 2, the maximum length is different;3, the record content is not allowed, VARCHAR will additionally record the length of the string. CHAR and VARCHAR types are similar, but they are saved and retrieved differently. They also differ in maximum length and whether trailing spaces are preserved. Case conversion is not performed during storage or retrieval. The length of CHAR and VARCHAR type declarations indicates the maximum number of characters you want to save. For example, CHAR(30) can take up 30 characters. CHAR column length is fixed to the length declared when the table is created. The length can be any value from 0 to 255. When CHAR values are saved, spaces are padded to the right of them to reach the specified length. When the CHAR value is retrieved, trailing spaces are removed. Case conversion is not performed during storage or retrieval. Values in VARCHAR columns are variable-length strings. Length can be specified as a value between 0 and 65,535. (The maximum valid length of VARCHAR is determined by the maximum line size and the character set used.) The overall maximum length is 65,532 bytes). In contrast to CHAR, VARCHAR values are saved as many characters as needed, plus one byte to record the length (two bytes if the column declaration is longer than 255). VARCHAR values are saved without padding. The trailing spaces remain when values are saved and retrieved, consistent with standard SQL. If the value assigned to a CHAR or VARCHAR column exceeds the maximum length of the column, the value is clipped to fit. If the truncated character is not a space, a warning is generated. Clipping non-white space characters causes an error (not a warning) and disables insertion of values by using strict SQL mode.

The above is what data types mysql has, Xiaobian believes that some knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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

Database

Wechat

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

12
Report