MySQL data type

Source: Internet
Author: User

The role of data types
1: Reduce error rate
2: Speed up the operation
Defines the meaning of a numeric representation inside a character
Like what
The ID int (10) indicates that the ID can store up to 10 digits, for example, 1234567890 of these values can be stored in the ID, but if you add a bit this number will not be stored in the ID, So it means 10, so you can only store 1234567890 so many bits, more than one is stored, the length of the data represented, not the storage space

CREATE TABLE Okdata (FTI tinyint,fsi smallint,fmi mediumint,fi int,fbi bigint);
mysql> desc Okdata;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| FTI | Tinyint (4) | YES | | NULL | |
| FSI | smallint (6) | YES | | NULL | |
| FMI | Mediumint (9) | YES | | NULL | |
| Fi | Int (11) | YES | | NULL | |
| FBI | bigint (20) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
INSERT into Okdata values (123456789,123456789,123456789,123456789,123456789);
+------+-------+---------+-----------+-----------+
| FTI | FSI | FMI | Fi | FBI |
+------+-------+---------+-----------+-----------+
| 127 | 32767 | 8388607 | 123456789 | 123456789 |
+------+-------+---------+-----------+-----------+
Above is the result of the query
Tinyint small integer maximum is only 127

Show warnings; View alarm Information
5.6.26 later version of the above INSERT statement can not be executed successfully, will be directly error, the rigor of a lot of good


Not rigorous 2
CREATE TABLE Ckdata2 (age tinyint);
INSERT into ckdata2 values (' Hello ');
Create an integer table, but insert the time is a string, the execution of the result is still inserted into the string, so that the non-rigor of the MySQL directly

Unsigned represents an unsigned integer that shows a positive integer
Zerofill represents a positive number.


mysql> desc ckdata3;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| Fi | Int (11) | YES | | NULL | |
| FIU | Int (Ten) unsigned | YES | | NULL | |
| Fiz | Int (Ten) unsigned Zerofill | YES | | NULL | |
| Fiuz | Int (Ten) unsigned Zerofill | YES | | NULL | |
+-------+---------------------------+------+-----+---------+-------+


Mysql> select * from Azerofill;
+------------+------------+------------+
| Fi | Fiz | Fiuz |
+------------+------------+------------+
| 11 | 011 | 0011 |
| 123456 | 123456 | 123456 |
| 2147483647 | 4294967295 | 4294967295 |
+------------+------------+------------+
When setting the value, if it is unsigned 0 filled, then all the values are turned into positive numbers, or half of them will become negative.

Floating point Type
Mainly has float< single precision, double< double precision >,decimal< precise designation >
float and double are floating point types, and the larger the number the less accurate
Decimal is a fixed-point number, often used to store financial wages, high-precision

Binary modifier: Distinguishes between character sizes, and compares char types in a binary way

The new version installs by default is the InnoDB engine, the old version is the MyISAM engine

Multiple fragments can affect the processing speed of the MyISAM engine, taking up disk space
InnoDB

Text type
Long text type, mainly used for posts, articles, comments and the like, enhanced version of the string, can be seen as the growth of varchar version

MySQL data type

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.