当前位置:网站首页>Detailed explanation of MySQL field types

Detailed explanation of MySQL field types

2022-06-09 04:34:00 User 9076598

MySQL Supports a large number of column types , It can be divided into 3 class : Numeric type 、 Date and time types and strings ( character ) type . Overview intentionally simplified , More detailed explanations should take into account additional information about specific column types , For example, you can specify the allowed format of the value . from MySQL The supported column types are listed below . The following code letters are used in the description :M Indicate the maximum display size . The largest legal display size is 255 . D Applies to floating-point types and indicates the number of digits following the decimal point . The most likely value is 30, But it should not be greater than M-2. square brackets (“[” and “]”) Indicates the part of the optional type modifier . Be careful , If you specify one as ZEROFILL,MySQL Will automatically increase for this column UNSIGNED attribute . TINYINT[(M)] [UNSIGNED] [ZEROFILL] A small integer . The signed range is -128 To 127, The unsigned range is 0 To 255. SMALLINT[(M)] [UNSIGNED] [ZEROFILL] A small integer . The signed range is -32768 To 32767, The unsigned range is 0 To 65535. MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] A medium-sized integer . The signed range is -8388608 To 8388607, The unsigned range is 0 To 16777215. INT[(M)] [UNSIGNED] [ZEROFILL] A normal size integer . The signed range is -2147483648 To 2147483647, The unsigned range is 0 To 4294967295. INTEGER[(M)] [UNSIGNED] [ZEROFILL] This is a INT A synonym for . BIGINT[(M)] [UNSIGNED] [ZEROFILL] A large integer . The signed range is -9223372036854775808 To 9223372036854775807, The unsigned range is 0 To 18446744073709551615. Be careful , All arithmetic operations are performed with signed BIGINT or DOUBLE Value completion , So you should not use more than 9223372036854775807(63 position ) Signed large integer of , Except bit function ! Be careful , When two parameters are INTEGER When the value of ,-、+ and * Will use BIGINT operation ! This means that if you take 2 A large integer ( Or from a function that returns an integer ), If the result is greater than 9223372036854775807, You can get unexpected results . A floating point number , Can't be unsigned , On a single precision floating point number , Its accuracy can be <=24, On a double precision floating point number , Is in 25 and 53 Between , These types are as follows FLOAT and DOUBLE The types are described below . FLOAT(X) There are corresponding FLOAT and DOUBLE The same range , But the display size and scale are undefined . stay MySQL3.23 in , This is a real floating point value . In earlier MySQL In the version ,FLOAT(precision) There are always 2 Decimal place . This syntax is for ODBC Compatibility . FLOAT[(M,D)] [ZEROFILL] One small ( Single precision ) Floating point number . Cannot be unsigned . The allowable value is -3.402823466E+38 To -1.175494351E-38,0 and 1.175494351E-38 To 3.402823466E+38. M Is the display width and D Is the number of decimal places . Without parameters FLOAT Or have <24 A parameter to represents a single precision floating-point number . DOUBLE[(M,D)] [ZEROFILL] A normal size ( Double precision ) Floating point number . Cannot be unsigned . The allowable value is -1.7976931348623157E+308 To -2.2250738585072014E-308、 0 and 2.2250738585072014E-308 To 1.7976931348623157E+308. M Is the display width and D It's the number of decimal places . Without a single parameter DOUBLE or FLOAT(X)(25 < = X < = 53) Represents a double precision floating point number . DOUBLE PRECISION[(M,D)] [ZEROFILL] REAL[(M,D)] [ZEROFILL] These are DOUBLE A synonym for . DECIMAL[(M[,D])] [ZEROFILL] One uncompressed (unpack) Floating point number of . Cannot be unsigned . Act like one CHAR Column :“ non-compressed ” Means that the number is stored as a string , Use one character for each bit of the value . decimal point , And for negative numbers ,“-” Sign not in M Middle computation . If D yes 0, Value will have no decimal point or fraction . DECIMAL The maximum range of values is DOUBLE identical , But for a given DECIMAL Column , The actual scope can be M and D Limited choice of . If D Omitted , It is set to 0. If M Be omitted , It is set to 10. Be careful , stay MySQL3.22 in ,M Parameters include symbols and decimal points . NUMERIC(M,D) [ZEROFILL] This is a DECIMAL A synonym for . DATE A date . The scope of support is '1000-01-01' To '9999-12-31'. MySQL With 'YYYY-MM-DD' Format to display DATE value , But it allows you to assign values to DATE Column . DATETIME A combination of date and time . The scope of support is '1000-01-01 00:00:00' To '9999-12-31 23:59:59'. MySQL With 'YYYY-MM-DD HH:MM:SS' Format to display DATETIME value , But it allows you to assign values to DATETIME The column of . TIMESTAMP[(M)] A time stamp . The scope is '1970-01-01 00:00:00' To 2037 Sometime in the year . MySQL With YYYYMMDDHHMMSS、YYMMDDHHMMSS、YYYYMMDD or YYMMDD Format to display TIMESTAMP value , Depends on whether M yes 14( Or omit )、12、8 or 6, But it allows you to assign values to TIMESTAMP Column . One TIMESTAMP Column for a record INSERT or UPDATE The date and time of the operation are useful , Because if you don't assign it to yourself , It is automatically set to the date and time of the most recent operation . You can give it a NULL Value to set it to the current date and time . TIME A time . The scope is '-838:59:59' To '838:59:59'.MySQL With 'HH:MM:SS' Format to display TIME value , But it allows you to assign values to TIME Column . YEAR[(2|4)] One 2 or 4 Year in bit number format ( The default is 4 position ). The allowable value is 1901 To 2155, and 0000(4 Potential year format ), If you use 2 position ,1970-2069( 70-69). MySQL With YYYY Format to display YEAR value , But it allows you to assign string or numeric values to YEAR Column . (YEAR Type in the MySQL3.22 Is a new type .) CHAR(M) [BINARY] A fixed length string , When storing , Always fill the right side with spaces to the specified length . M The range is 1 ~ 255 Characters . When the value is retrieved , Trailing space removed . CHAR Values are sorted and compared in a case insensitive manner according to the default character set , Unless given BINARY key word . NATIONAL CHAR( Short form NCHAR) yes ANSI SQL The way to define CHAR Columns should use the default character set . This is a MySQL Default .CHAR yes CHARACTER An abbreviation of . [NATIONAL] VARCHAR(M) [BINARY] A variable length string . Be careful : When the value is stored , Trailing space removed ( This is different from ANSI SQL standard ). M The range is 1 ~ 255 Characters . VARCHAR Values are sorted and compared in a case insensitive manner according to the default character set , Unless given BINARY Keyword value . VARCHAR yes CHARACTER VARYING An abbreviation . TINYBLOB TINYTEXT One BLOB or TEXT Column , Maximum length is 255(2^8-1) Characters . BLOB TEXT One BLOB or TEXT Column , Maximum length is 65535(2^16-1) Characters . MEDIUMBLOB MEDIUMTEXT One BLOB or TEXT Column , Maximum length is 16777215(2^24-1) Characters . LONGBLOB LONGTEXT One BLOB or TEXT Column , Maximum length is 4294967295(2^32-1) Characters . ENUM('value1','value2',...) enumeration . A string object with only one value , This value formula is selected from the list of and values 'value1'、'value2', ..., or NULL. One ENUM Most can have 65535 Different values . SET('value1','value2',...) A collection . A string object that can have zero or more values , Each of these must be from a list of values 'value1', 'value2', ... elect . One SET Most can have 64 Members .

原网站

版权声明
本文为[User 9076598]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021700496491.html