SQL數據類型 (SQL Data Types)
Each column in a database table is required to have a name and a data type.
數據庫表中的每一列都必須具有名稱和數據類型。
An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.
SQL開發人員必須確定在創建表時將在每一列內存儲的數據類型。 數據類型是SQL理解每列內部期望的數據類型的指南,并且還確定SQL將如何與存儲的數據進行交互。
MySQL數據類型 (MySQL Data Types)
SQL general data types consist of the following:
SQL常規數據類型包括以下內容:
- A text- and/or numeric-based value, often referred to as a STRING 基于文本和/或數字的值,通常稱為“ STRING”
- A numeric-only value, often referred to as an INTEGER 僅數字值,通常稱為INTEGER
- A calendar- and/or clock-based value, often reffered to as DATE or TIME 基于日歷和/或時鐘的值,通常為DATE或TIME
- A database-specific value such as a boolean (two-option) flag, an array that stores multiple values within one data point 特定于數據庫的值,例如布爾(雙選項)標志,該??數組在一個數據點內存儲多個值
文字數據類型: (Text data types:)
Data type | Description |
---|---|
CHAR(size) | Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters |
VARCHAR(size) | Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters. Note: If you put a greater value than 255 it will be converted to a TEXT type |
TINYTEXT | Holds a string with a maximum length of 255 characters |
TEXT | Holds a string with a maximum length of 65,535 characters |
BLOB | For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data |
MEDIUMTEXT | Holds a string with a maximum length of 16,777,215 characters |
MEDIUMBLOB | For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data |
LONGTEXT | Holds a string with a maximum length of 4,294,967,295 characters |
LONGBLOB | For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data |
ENUM(x,y,z,etc.) | Let you enter a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted. Note: The values are sorted in the order you enter them. You enter the possible values in this format: ENUM(‘X’,‘Y’,‘Z’) |
SET | Similar to ENUM except that SET may contain up to 64 list items and can store more than one choice |
數據類型 | 描述 |
---|---|
CHAR(大小) | 持有固定長度的字符串(可以包含字母,數字和特殊字符)。 固定大小在括號中指定。 最多可存儲255個字符 |
VARCHAR(大小) | 包含可變長度的字符串(可以包含字母,數字和特殊字符)。 最大大小在括號中指定。 最多可以存儲255個字符。 注意:如果您輸入的值大于255,它將轉換為TEXT類型 |
細語 | 包含最大長度為255個字符的字符串 |
文本 | 包含最大長度為65,535個字符的字符串 |
BLOB | 對于BLOB(二進制大對象)。 最多可容納65,535個字節的數據 |
中文字 | 包含最大長度為16,777,215個字符的字符串 |
中號 | 對于BLOB(二進制大對象)。 最多可容納16,777,215字節數據 |
長文本 | 包含最大長度為4,294,967,295個字符的字符串 |
龍寶 | 對于BLOB(二進制大對象)。 最多可容納4,294,967,295字節的數據 |
枚舉(x,y,z等) | 讓您輸入可能值的列表。 您最多可以在ENUM列表中列出65535個值。 如果插入的值不在列表中,則將插入空白值。 注意:值將按照您輸入的順序進行排序。 您可以使用以下格式輸入可能的值:ENUM('X','Y','Z') |
組 | 與ENUM相似,但SET最多可以包含64個列表項,并且可以存儲多個選項 |
數字數據類型: (Number data types:)
Data type | Description |
---|---|
TINYINT(size) | -128 to 127 normal. 0 to 255 UNSIGNED*. The maximum number of digits may be specified in parenthesis |
SMALLINT(size) | -32768 to 32767 normal. 0 to 65535 UNSIGNED*. The maximum number of digits may be specified in parenthesis |
MEDIUMINT(size) | -8388608 to 8388607 normal. 0 to 16777215 UNSIGNED*. The maximum number of digits may be specified in parenthesis |
INT(size) | -2147483648 to 2147483647 normal. 0 to 4294967295 UNSIGNED*. The maximum number of digits may be specified in parenthesis |
BIGINT(size) | -9223372036854775808 to 9223372036854775807 normal. 0 to 18446744073709551615 UNSIGNED*. The maximum number of digits may be specified in parenthesis |
FLOAT(size,d) | A small number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter |
DOUBLE(size,d) | A large number with a floating decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter |
DECIMAL(size,d) | A DOUBLE stored as a string , allowing for a fixed decimal point. The maximum number of digits may be specified in the size parameter. The maximum number of digits to the right of the decimal point is specified in the d parameter |
數據類型 | 描述 |
---|---|
天晴(尺碼) | -128至127正常。 0至255 UNSIGNED *。 可以在括號中指定最大位數 |
SMALLINT(大小) | -32768至32767正常。 0到65535 UNSIGNED *。 可以在括號中指定最大位數 |
MEDIUMINT(大小) | -8388608至8388607正常。 0到16777215 UNSIGNED *。 可以在括號中指定最大位數 |
INT(尺寸) | -2147483648至2147483647正常。 0至4294967295 UNSIGNED *。 可以在括號中指定最大位數 |
BIGINT(大小) | -9223372036854775808至9223372036854775807正常。 0至18446744073709551615未簽名*。 可以在括號中指定最大位數 |
浮法(尺寸,d) | 一個帶有浮點小數點的小數字。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定 |
雙(大小,d) | 帶有小數點浮點的大數。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定 |
十進制(大小,d) | 以字符串形式存儲的DOUBLE,允許使用固定的小數點。 可以在size參數中指定最大位數。 小數點右邊的最大位數在d參數中指定 |
日期數據類型: (Date data types:)
Data type | Description |
---|---|
DATE() | A date. Format: YYYY-MM-DD Note: The supported range is from ‘1000-01-01’ to ‘9999-12-31’ |
DATETIME() | A date and time combination. Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’ |
TIMESTAMP() | A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch (‘1970-01-01 00:00:00’ UTC). Format: YYYY-MM-DD HH:MI:SS Note: The supported range is from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-09 03:14:07’ UTC |
TIME() | A time. Format: HH:MI:SS Note: The supported range is from ‘-838:59:59’ to ‘838:59:59’ |
YEAR() | A year in two-digit or four-digit format. Note: Values allowed in four-digit format: 1901 to 2155. Values allowed in two-digit format: 70 to 69, representing years from 1970 to 2069 |
數據類型 | 描述 |
---|---|
日期() | 一個約會。 格式:YYYY-MM-DD注:支持的范圍是從“ 1000-01-01”到“ 9999-12-31” |
約會時間() | 日期和時間組合。 格式:YYYY-MM-DD HH:MI:SS注意:支持的范圍是從“ 1000-01-01 00:00:00”到“ 9999-12-31 23:59:59” |
TIMESTAMP() | 時間戳記。 TIMESTAMP值存儲為自Unix紀元('1970-01-01 00:00:00'UTC)以來的秒數。 格式:YYYY-MM-DD HH:MI:SS注意:支持的范圍是從UTC的“ 1970-01-01 00:00:01”到UTC的“ 2038-01-09 03:14:07” |
時間() | 一次 格式:HH:MI:SS注意:支持的范圍是'-838:59:59'到'838:59:59' |
年() | 兩位數字或四位數字格式的年份。 注意:允許以四位數字格式的值:1901到2155。允許以兩位數格式的值:70到69,表示從1970到2069的年份。 |
Finally, there are a few other data types that you will use:
最后,還有一些其他數據類型將要使用:
其他數據類型 (Other Data Types)
Data type | Description |
---|---|
BOOLEAN | Stores TRUE or FALSE values |
ARRAY | A set-length and ordered collection of elements |
MULTISET | A variable-length and unordered collection of elements |
XML | Stores XML data |
數據類型 | 描述 |
---|---|
BOOLEAN | 存儲TRUE 或FALSE 值 |
ARRAY | 元素的集合長度和有序集合 |
MULTISET | 可變長度和無序元素集合 |
XML | 存儲XML數據 |
翻譯自: https://www.freecodecamp.org/news/sql-data-types-mysql/