mysql supported data types and comparison

1. Data type
numeric type. The
strict numeric type
integer
supports specifying the display width in the parentheses after the type. If not specified, the default is int(11)
with zerofill, which means that 0 fills
only the attributes of integer types: auto_increment, generally starting from 1. , Each row increases by 1, and there is at most one auto-increment column in a table, which is defined as not null and defined as primary key or unique
decimal
when the number of reserved digits is based on the precision and scale, and will not be rounded to
numeric (and Same as decimal)
approximate numeric type
float
real
double precision

bit  
	用来存放位数据,二进制数据(查看位字段值 二进制:Bin   十六进制:hex)
	select bin(id) from tbname;

Decimals: (M, D) A total of M digits are displayed (integer digits + decimal digits total M digits) precision and scale)
floating-point numbers (no precision and scale will be stored according to the actual precision scale, if there is, and exceed the precision scale The degree will be automatically rounded)
float
double
fixed-point number (if the fixed-point number is not written, the operation will be performed according to the default value (10, 0). If the precision and scale are written, it will be inserted according to the precision and scale. The data will be inserted according to the scale. Degree insertion, although the data is inserted, there will be a warning)
Decimal
is stored in mysql as a string, which is more accurate than floating point numbers. It is used to represent currency and other high-precision data. The precision is not specified. The default integer bit 10, the default number of decimal places to 0
string
char
length of fixed length for the creation of a declaration
will delete trailing spaces
varchar
column is variable length strings
will retain trailing spaces
binary
varbinary
BLOB (binary string)
Text
and varchar are the same. Text requires two bytes to record the total number of bytes in the field. Varchar's query speed is faster than text (if the maximum length of the attribute is not known, text is suitable)
enum (enumeration)
. The value needs to be displayed and specified by enumeration when the table is created (create table t1 (gender enum("m","f"))) The
enum type ignores case, and stores m and F will convert them to uppercase
For the first value into a specified range not enum values, and did not return a warning, but the insertion enumerated
enum types only a single value selected from the set value, together can not take a plurality of values
SET
SET type may allow the set of values Any combination of one or more elements
is not allowed to be injected into the above set type for
repeated values ​​beyond the allowable range , such as ('a','b','a'), only the a is saved once, and the result after writing is ('a','b')

Date and time
data (year, month, day)
time (hour, minute, second)
datatime (year, month, day, hour, minute, and second)
year (year)
occupies less space than DATA
timestamp (year, month, day, hour, minute, and second)
often insert or update the date for the current system return After displaying "YYYY-MM-DD HH:MM:SS" timestamp is related to the time zone (current_timestamp represents the system date). The timestamp type field can only have one column and the default value is current_timestamp

2. Comparison:
char and varchar: the
length of char is fixed to the length of the milk when it is created, varchar is a variable length.
Insert a value with spaces, char will automatically delete the trailing spaces, and varchar will retain
binary and varbinary (stored in the table The middle is binary data):
Both are similar to char and varchar, the difference is that they contain binary strings instead of non-binary strings
float and double:
double has high accuracy,
double consumes twice as much memory as float
double The operation speed is much slower than float.
The difference between timestamp and datetime:
The time range supported by timestamp is relatively small; the value range is to a certain day in 2038, which is not suitable for storing the relatively long date
table. The first timestamp column in the table is automatically set to The current date and time, the default value of other columns is timestamp type will be set to 0, if forced to set timestamp, will report an error
timestamp insertion and query are affected by the local time zone, can reflect the actual date, and datetime only
The attribute of timestamp that can reflect the local time zone when inserting is greatly affected by the MySQL version and the server sqlmode

3. Time representation The following ways of writing are the same after being inserted into the table and displayed
as'YYYY -MM-DD HH:MM:SS': '2007-9-3 12:10:10'
'2007/9 /3 12+10+10'
'20070903121010'
20070903121010

Guess you like

Origin blog.csdn.net/weixin_43202081/article/details/107936806