Here integer type along with minimum maximum value length and storage in byte.
In contrast to CHAR (0 to 65,535), VARCHAR (length 0 to 65,535) values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
varchar = 1 byte which is fix + number of characters( 0 to 255) byte
varch = 1+4 = 5 byte (abcd is 4 character+1 = 5 byte)
varchar = 2 byte which is fix + number of characters(256 to 65535) byte
For more text type :
For other field/column type
Type | Storage | Minimum Value | Maximum Value |
---|---|---|---|
(Bytes) | (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 |
In contrast to CHAR (0 to 65,535), VARCHAR (length 0 to 65,535) values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
Value | CHAR(4) | Storage Required | VARCHAR(4) | Storage Required |
---|---|---|---|---|
'' | ' ' | 4 bytes | '' | 1 byte |
'ab' | 'ab ' | 4 bytes | 'ab' | 3 bytes |
'abcd' | 'abcd' | 4 bytes | 'abcd' | 5 bytes |
'abcdefgh' | 'abcd' | 4 bytes | 'abcd' | 5 bytes |
varchar = 1 byte which is fix + number of characters( 0 to 255) byte
varch = 1+4 = 5 byte (abcd is 4 character+1 = 5 byte)
varchar = 2 byte which is fix + number of characters(256 to 65535) byte
For more text type :
TEXT
|
String length + 2 bytes
|
A string with a maximum length of 65,535 characters
|
MEDIUMTEXT
|
String length + 3 bytes
|
A string with a maximum length of 16,777,215 characters
|
LONGTEXT
|
String length + 4 bytes
|
A string with a maximum length of 4,294,967,295 characters
|
FLOAT[Length, Decimals]
|
4 bytes
|
A small number with a floating decimal point
|
DOUBLE[Length, Decimals]
|
8 bytes
|
A large number with a floating decimal point
|
DECIMAL[Length, Decimals]
|
Length + 1 or 2 bytes
|
A DOUBLE stored as a string, allowing for a fixed decimal point
|
DATE
|
3 bytes
|
In the format of YYYY-MM-DD
|
DATETIME
|
8 bytes
|
In the format of YYYY-MM-DD HH:MM:SS
|
TIMESTAMP
|
4 bytes
|
In the format of YYYYMMDDHHMMSS; acceptable range starts in 1970 and ends in the year 2038
|
TIME
|
3 bytes
|
In the format of HH:MM:SS
|
No comments:
Post a Comment