Mariadb learning summary (3): data types
Data type-> is an abstraction of a data classification with the same attributes and properties.
For example:
A string is a string composed of characters... In computers, substrings can be divided and new characters can be added at the end of the string. However, such operations can only operate on string data, not on string data. Operate on integers.
Numeric type, the Arabic numerals we are most exposed to, can be used for arithmetic operations, logical operations and other operations
MySQL supports multiple types, which can be roughly divided into three categories: numerical, date/time and string (character) types.
1. For integer types, you can limit their length, the format is as follows:
整数类型[(M)] [SIGNED | UNSIGNED | ZEROFILL]
M is the number of digits in the number. For example, TINYINT(3) can only store three digits, and the number of digits should not exceed the range it can represent
SIGNED: The default is signed number
UNSIGNED: specified as an unsigned number
ZEROFILL: When M bits are not satisfied, the front is filled with 0 and becomes an unsigned number
2. For floating point numbers, the overall number of digits and the number of decimal places can be limited
(FLOAT|DOUBLE)[(M,D)] [SIGNED | UNSIGNED | ZEROFILL]
M is the total number of digits, D is the number of digits after the decimal point
ZEROFILL has the same effect as UNSIGNED for floating point types
MariaDB [mydb]> DESC t1; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | c1 | float(5,2) | YES | | NULL | | | c2 | double(10,3) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) MariaDB [mydb]> INSERT INTO t1 VALUES(23.5,12.34566777); Query OK, 1 row affected (0.01 sec) MariaDB [mydb]> SELECT * FROM t1; //这里可以看到,在其后补了0 +-------+--------+ | c1 | c2 | +-------+--------+ | 23.50 | 12.346 | +-------+--------+ 1 row in set (0.00 sec)
Format abbreviation: Date and time format, in addition to the standard format, it also supports loose 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/01/01'),(180101); Query OK, 5 rows affected (0.01 sec) Records: 5 Duplicates: 0 Warnings: 0 MariaDB [mydb]> SELECT c1 FROM datetable; +------------+ | c1 | +------------+ | 2018-01-01 | | 2018-01-01 | | 2018-01-01 | | 2018-01-01 | | 2018-01-01 | +------------+ 5 rows in set (0.00 sec)
For TIME type: 'D HH:MM:SS', 'HH:MM:SS', 'HH:MM', 'D HH:MM', 'D HH', 'SS', 'HHMMSS'
D stands for day, which is TIME+D*24
MariaDB [mydb]> INSERT INTO datetable(c2) VALUES -> ('12:20:20'),('1 12:20:20'), -> ('12:20'),('1 12'),('20'),('122020'), -> (122020); Query OK, 7 rows affected (0.03 sec) Records: 7 Duplicates: 0 Warnings: 0 MariaDB [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 the two formats DATETIME and TIMESTAMP, they are the abbreviations of the above time abbreviation format, for example:
20180101122020 -> '2018-01-01 12:20:20'
For the format TIMESTAMP, which is more commonly used, it should be said that it stores the number of milliseconds from '1970-01-01 00:00:00' to the storage time. Its default value can be CURRENT_TIMESTAMP or its synonym: CURRENT_TIMESTAMP() , NOW(), LOCALTIME, LOCALTIME(), LOCALTIMESTAMP,LOCALTIMESTAMP()
CHAR and VARCHAR types are similar, but they are saved and retrieved differently. They also differ in terms of their maximum length and whether trailing spaces are preserved. No case conversion is performed during storage or retrieval.
BINARY and VARBINARY classes are similar to CHAR and VARCHAR, except that they contain binary strings instead of non-binary strings. That is, they contain byte strings rather than character strings. This means that they do not have a character set, and sorting and comparison are based on the numeric value of the column value bytes.
A BLOB is a binary large object that can hold a variable amount of data:
There are 4 BLOB types: TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB. They only differ in the maximum length they can hold a value.
There are 4 TEXT types: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. These correspond to 4 BLOB types, with the same maximum length and storage requirements.
Enumeration type: ENUM('value1','value2',...)
Storage bytes: Because it stores element numbers, elements 0-255 only occupy one byte, while 255-65535 occupy two elements
The above is the detailed content of Mariadb learning summary (3): data types. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.
