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 Mariadb data types

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of "what are the Mariadb data types". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what are the Mariadb data types" can help you solve the problem.

MariaDB is a branch of MySQL database, using almost the same method as MySQL, including commands, interfaces, usage, etc., according to the official introduction, before the version of MariaDB 5.5, the desired features are completely inherited from MySQL, so people who use MariaDB 5.5 will learn all the functions of MariaDB from MySQL 5.5.

Data type

Data type-> is an abstraction of data classification with the same attributes and properties.

For example: a string is a string of characters that is called a string. In the computer, you can divide substrings and add new characters at the end of the string, but this kind of operation can only manipulate string data, not integers. Digital type, the Arabic numerals that we most often come into contact with, can perform arithmetic operations, logical operations and other operations.

Data types in Mysql

MySQL supports many types, which can be roughly divided into three types: numeric, date / time, and string (character) types.

Numerical type

1. For integer types, you can limit their length as follows: integer type [(M)] [SIGNED | UNSIGNED | ZEROFILL]

M is the number of digits, such as TINYINT (3), can only store three digits, the number of digits should not exceed the range it can represent SIGNED: the default is the signed number UNSIGNED: specified as the unsigned number ZEROFILL: when the M bit is not satisfied, it is preceded by 0 and becomes unsigned.

two。 For floating-point numbers, you can limit the overall number of digits and the number of decimal places

(FLOAT | DOUBLE) [(MForce D)] [SIGNED | UNSIGNED | ZEROFILL]

M is the total number of digits and D is the number of digits after the decimal point. ZEROFILL has the same effect as UNSIGNED for floating point.

MariaDB [mydb] > DESC T1 +-+ | Field | Type | Null | Key | Default | Extra | +-+-- -+ | C1 | float (5 sec 2) | YES | | NULL | c2 | double (10Lei3) | YES | | NULL | | +-+-+ 2 rows in set (0.00 sec) MariaDB [mydb] > INSERT INTO T1 VALUES (23.5 Magi 12.34566777) Query OK, 1 row affected (0. 01 sec) MariaDB [mydb] > SELECT * FROM T1; / / you can see here that the date and time type of row in set (0.00 sec) is followed by the addition of 0 sec. | C1 | c2 | +-+-+ | 23.50 |

Format abbreviation: date-time format that supports loose formats in addition to standard formats.

Create a test table with the following structure:

MariaDB [mydb] > desc datetable +-+-+ | Field | Type | Null | Key | Default | Extra | +- -+-+ | C1 | date | YES | | NULL | | c2 | time | YES | | NULL | c3 | datetime | YES | | NULL | c4 | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | +-| -+

For date type: YY-MM-DD, YYMMDD, YYYY/MM/DD

MariaDB [mydb] > INSERT INTO datetable (C1) VALUES ('2018-01-01'), ('18-01-01'),-> ('180101'), ('2018 Records 01 sec), (180101); Query OK, 5 Duplicates: 0 Warnings: 0MariaDB [mydb] > SELECT C1 FROM datetable +-+ | C1 | +-01-01 | 0-01-01 | | 2018-01-01 | 2018-01-01 | | 2018-01-01 | | 2018-01-01 | +-+ 5 rows in set (2018 sec)

For time type:'D HH:MM:SS', 'HH:MM:SS',' HH:MM','D HH:MM','D HH', 'SS',' HHMMSS' D represent days, that is, TIME+D*24

MariaDB [mydb] > INSERT INTO datetable (c2) VALUES-> ('12 sec 20'), ('1 12 VALUES 20'),-> ('12 VALUES 20'), ('12 VALUES 20'), ('1 12), ('20'), ('122020'),-> (122020); Query OK, 7 Duplicates (0.03 sec) Records: 7 Warnings: 0 Warnings: 0MariaDB [mydb] > SELECT c2 FROM datetable +-+ | c2 | +-+ | 12:20:20 | | 36:20:20 | | 12:20:00 | 36:00:00 | 00:00:20 | 12:20:20 | | 12:20:20 | +-+ 7 rows in set (0.00 sec)

For DATETIME and TIMESTAMP, it is an abbreviation for the above time shorthand format, for example:

20180101122020-> '2018-01-0112: 20purl 20'

It should be said that TIMESTAMP stores the number of milliseconds from '1970-01-01 00 to storage time. Its default value can be CURRENT_TIMESTAMP or its synonyms: CURRENT_TIMESTAMP (), NOW (), LOCALTIME, LOCALTIME (), LOCALTIMESTAMP,LOCALTIMESTAMP ().

String type

CHAR and VARCHAR types are similar, but they are saved and retrieved differently. They are also different in terms of maximum length and whether trailing spaces are retained. No case conversion occurs during storage or retrieval.

The BINARY and VARBINARY classes are similar to CHAR and VARCHAR, except that they contain binary strings rather than non-binary strings. That is, they contain byte strings instead of character strings. This means that they do not have a character set, and sort and compare numeric values based on column value bytes.

BLOB is a large binary object that can hold a variable amount of data: there are four BLOB types: TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. They just differ in the maximum length of the allowable value. There are four types of TEXT: TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to four BLOB types with the same maximum length and storage requirements.

Other types

Enumerated type: ENUM ('value1','value2', …) Storage bytes: because it stores element numbers, it accounts for only one byte for 0,255elements and 65535 for two elements.

This is the end of the introduction to "what are the Mariadb data types". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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

Development

Wechat

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

12
Report