SQL数据类型说明和MySQL语法示例

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常规数据类型包括以下内容:

  1. A text- and/or numeric-based value, often referred to as a STRING

    基于文本和/或数字的值,通常称为“ STRING”
  2. A numeric-only value, often referred to as an INTEGER

    仅数字值,通常称为INTEGER
  3. A calendar- and/or clock-based value, often reffered to as DATE or TIME

    基于日历和/或时钟的值,通常为DATE或TIME
  4. 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 typeDescription
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
TINYTEXTHolds a string with a maximum length of 255 characters
TEXTHolds a string with a maximum length of 65,535 characters
BLOBFor BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
MEDIUMTEXTHolds a string with a maximum length of 16,777,215 characters
MEDIUMBLOBFor BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data
LONGTEXTHolds a string with a maximum length of 4,294,967,295 characters
LONGBLOBFor 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’)
SETSimilar 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 typeDescription
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 typeDescription
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 typeDescription
BOOLEANStores TRUE or FALSE values
ARRAYA set-length and ordered collection of elements
MULTISETA variable-length and unordered collection of elements
XMLStores XML data
数据类型 描述
BOOLEAN 存储TRUEFALSE
ARRAY 元素的集合长度和有序集合
MULTISET 可变长度和无序元素集合
XML 存储XML数据

翻译自: https://www.freecodecamp.org/news/sql-data-types-mysql/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值