Original: https://www.cnblogs.com/jennyyin/p/7895010.html
Numeric type
Types of |
size |
range (signed) |
range (unsigned) |
use |
TINYINT |
1 byte |
(-128,127) |
(0,255) |
small integer value |
SMALLINT |
2 bytes |
(-32 768,32 767) |
(0,65 535) |
large integer value |
MEDIUMINT |
3 bytes |
(-8 388 608,8 388 607) |
(0,16 777 215) |
large integer value |
INT or INTEGER |
4 bytes |
(-2 147 483 648,2 147 483 647) |
(0,4 294 967 295) |
large integer value |
BIGINT |
8 bytes |
(-9 233 372 036 854 775 808,9 223 372 036 854 775 807) |
(0,18 446 744 073 709 551 615) |
very large integer value |
FLOAT |
4 bytes |
(-3.402 823 466 E + 38 , -1.175 494 351 E-38) , 0 , (1.175 494 351 E-38,3.402 823 466 351 E + 38) |
0 , (1,175 494 351 E-38,3,402 823 466 E + 38) |
single-precision |
DOUBLE |
8 bytes |
(-1.797 693 134 862 315 7 E + 308 , -2.225 073 858 507 201 4 E-308) , 0 , (2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E + 308) |
0 , (2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E + 308) |
Double-precision |
string
String types refer to CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM, and SET. This section describes how these types work and how to use them in queries.
char和varchar:
1. char(n) If the number of stored characters is less than n, it will be filled with spaces, and the spaces will be removed when querying. Therefore, the string stored in char type cannot have spaces at the end, and varchar is not limited to this.
2. char(n) fixed length, char(4) will occupy 4 bytes no matter how many characters are stored, varchar is the actual number of characters stored + 1 byte (n<=255) or 2 bytes (n>255), so varchar(4), storing 3 characters will occupy 4 bytes.
3. The string retrieval speed of char type is faster than that of varchar type.
varchar and text:
1. varchar can be specified n, text cannot be specified, the internal storage varchar is the actual number of characters stored + 1 byte (n<=255) or 2 bytes (n>255), text is the actual number of characters + 2 bytes.
2. The text type cannot have a default value.
3. varchar can directly create an index, and text creates an index to specify how many characters before it is created. The varchar query is faster than the text, and the index of the text does not seem to work when the index is created.
Types of |
size |
use |
CHAR |
0-255 bytes |
fixed-length string |
VARCHAR |
0-65535 bytes |
variable length string |
TINYBLOB |
0-255 bytes |
binary string of up to 255 characters |
TINYTEXT |
0-255 bytes |
short text string |
BLOB |
0-65 535 bytes |
long text data in binary form |
TEXT |
0-65 535 bytes |
long text data |
MEDIUMBLOB |
0-16 777 215 bytes |
Medium-length text data in binary form |
MEDIUMTEXT |
0-16 777 215 bytes |
medium length text data |
LONGBLOB |
0-4 294 967 295 bytes |
Very large text data in binary form |
LONGTEXT |
0-4 294 967 295 bytes |
very large text data |
datetime type
Date and time types that represent time values are DATETIME, DATE, TIMESTAMP, TIME, and YEAR.
Types of |
size |
Scope |
Format |
use |
DATE |
3 bytes |
1000-01-01/9999-12-31 |
YYYY-MM-DD |
date value |
TIME |
3 bytes |
'-838:59:59'/'838:59:59' |
HH:MM:SS |
time value or duration |
YEAR |
1 byte |
1901/2155 |
YYYY |
year value |
DATETIME |
8 bytes |
1000-01-01 00:00:00/9999-12-31 23:59:59 |
YYYY-MM-DD HH:MM:SS |
Mixed date and time values |
TIMESTAMP |
4 bytes |
1970-01-01 00:00:00/2038 The end time is 2147483647 seconds, 2038-1-19 11:14:07 Beijing time, January 19, 2038 03:14:07 GMT |
YYYYMMDD HHMMSS |
mixed date and time values, timestamp |
binary
boolean: bit
bit represents 1 binary bit
bit(8) represents 8 binary bits
gender can be defined as 0, 1 without using male or female string
data to logically delete
the state of a car parked in the garage
all based on Data in both states can be stored using 0,1.