Article Directory
Foreword '· ᴗ · `
- In this part will help you learn almost all data types used in the database and tell you which used what look like
Several basic data types
Note varchar (5) refers to the five characters not bytes! ! Indeed byte characters are generally only our previous LENGTH () function ( so-humanity )
Code | Explanation |
---|---|
int | Plastic |
double float | Float |
char | Fixed length character string |
varchar | Variable-length string |
text | Longer string |
date | date |
time | time |
timestamp | Timestamp |
We summarize ...
- String
- Short string
- Variable VARCHAR (n-)
n-: 65535 ~. 1
space-saving
CPU performance loss is large (to be calculated)
for the case of large volume change character - Fixed char (n-)
n-: 255. 1 ~
save CPU performance
wasted space
for a fixed length of the case
- Variable VARCHAR (n-)
- Long strings
- blob Audio Images
- long text fields (such as Bowen)
- Short string
- Numeric
- Integer INT
- Decimal
- Float double
- Fixed-point decimal
places for the accuracy of such stable money
- Date type
- Timestamp timestamp
affect the time zone of - Datetime time
is not affected by time zone - date Date
- Minutes and seconds when time specific time
- Timestamp timestamp
- Enumeration type ENUM
Timestamp vs datetime
We can create a table is a timestamp is a datetime
CREATE TABLE table1(
t1 DATETIME,
t2 TIMESTAMP
);
Then INSERT INTO table1 VALUES(NOW(),NOW());
table1 is that just created a table
Then we use SET time_zone='+10:00'
to change our time zone to the East Area 10,
we are the East eight districts do not believe you:
SHOW VARIABLES LIKE 'time_zone';
Enumeration type ENUM
ENUM enumerate
we can define a data cable, such as limited circumstances sex between men and women:
CREATE TABLE table1(c1 ENUM('男','女'))
Plastic
In fact, that is commonly used INT (n) n refers to the character n is the number of bits
below are other types of plastic size:
If the insert data exceeds the scope of this report is out of range error
name | Byte count | The maximum range |
---|---|---|
Tinyint | 1 | 2^8 |
Smallint | 2 | 2^8*2 |
Mediumint | 3 | 2^8*3 |
Int/integar | 4 | 2^8*4 |
Bigint | 8 | 2^8*8 |
Also to mention two keywords:
-
UNSIGNED is unsigned general default is signed
unsigned is expanding to double the size of the data (twice the original)
Why twice? Well no sign bit -
ZEROFILL is filled with zeros to fill gaps, such as 0 so 123--> 00,000,123 When INT (8)
Floating-point fixed-point
As the name suggests floating decimal floating-point values such as from 123.4 -> 123.400 points can only be given, however you add 0.01 123.4 or 123.4
which is particularly suitable for fixed-point money - in the form of both 000.00 decimal places fixed
Specifically related to computer composition principle operating system
The number of computers in addition to integer, decimal there. How to determine the position of the decimal point of it? There are generally two methods:
one is the fixed decimal point position is predetermined, known as fixed-point numbers.
Another is the location of the decimal point is not fixed, can float, float referred to.
- Usually fixed points to an integer and decimal fraction, referred to as fixed-point and fixed-point fractional integers .
- For, there are number of fractional part of both the integer part, generally expressed float.
Why? To facilitate the calculation ah !
Of course, use fixed-point calculation designated less CPU
can not it a big move with a fixed - floating-point operations
Fixed-point arithmetic:
If the same decimal point position directly adding just fine
but different decimal point position it?
Floating-point calculations can solve a big problem fixed-point decimal point position calculation record
So in general we actually use it with a pure fixed-point decimal fixed-point integer arithmetic convenient
than pure decimal floating point or integer to solve
Summary'◡`
This section on the basis of an in-depth talk about the fact when talking about the type of data used to look at the line does not need to remember only need to remember common :)
Next stop: MySQL database learning (twenty-five) - DDL (iii) constraints - constraints column-level table-level constraint syntax
In addition,
-
Well I want to learn database system?
MySQL column -
python so fire you want to play with python-depth study of a simple application thing? I can see the column continues to update oh:
Python application -
Child before doing all adults choose to be! Backend interested? Accept it now :)
hands-on learning with your back-end (server) -
Thank you, big brother support! Meng new courtesy :)