Pages

Monday 6 January 2020

SQL Data Type

String Data Type
String Data Type

Storage/
MAX_SIZE(Byte)
Example
Remark
Character
CHAR
Fixed/255
CHAR(5)
50% faster
Variable character
VARCHAR
Variable/65,535
VARCHAR(5)
a lot more responsive to the data value inserted
ENUM
(enumeration)
ENUM

ENUM(‘M’,’F’)
MySQL will show an error if you attempt to insert any value  different from "M" or "F"

Numeric Data Type
Integer
Fixed-point
Floating-point

Integer
Integer data types are ‘signed’ by default.
If you want to use a range containing only positive, ‘unsigned’ values, you would have to specify this in your query.
Numeric Data Type
Size(byte)
           MIN_VALUE
     (signed/unsigned)
              MIN_VALUE
         (signed/unsigned)
TINYINT
1
-128
127
0
255
SMALLINT
2
-32,768
32,767
0
65,535
MEDIUMINT
3
-8,388,608
8,388,607
0
16,777,215
INT
4
-2,147,483,648
2,147,483,647
0
4,294,967,295
BIGINT
8
-9,223,372,036,854,775,808
9,223,372,036,854,775,807
0
18,446,744,073,709,551,615

Fixed-point
DECIMAL
NUMERIC
DECIMAL(P, S)
e.g. DECIMAL(5,3)
10.523, here precision is 5 and scale is 3.
367.875, here precision is 6 and scale is 3

Floating-point
Floating-Point Data Type
Size(byte)
Precision
Max number of digits
FLOAT
4
Single
23
DOUBLE
8
Double
53

Next Topic: JOINS