A2-03-03.DDL-MySQL Data Types

转载自:http://www.mysqltutorial.org/mysql-data-types.aspx

MySQL Data Types

 

Summaryin this tutorial, you will learn about MySQL data types and how to use them effectively in designing database in MySQL.

A database table contains multiple columns with specific data types such as numeric or string. MySQL provides more data types other than just numeric or string. Each data type in MySQL can be determined by the following characteristics:

  • The kind of values it represents.
  • The space that takes up and whether the values is a fixed-length or variable length.
  • The values of the data type can be indexed or not.
  • How MySQL compares the values of a specific data type.

MySQL Data Types

Download MySQL Data Types Overview

MySQL numeric data types

In MySQL, you can find all SQL standard numeric types including exact number data type and approximate numeric data types including integer, fixed-point and floating point. In addition, MySQL also hasBIT data type for storing bit values. Numeric types can be signed or unsigned except for the BIT type.

The following table shows the summary of numeric types in MySQL:

Numeric TypesDescription
 TINYINTA very small integer
 SMALLINTA small integer
 MEDIUMINTA medium-sized integer
 INTA standard integer
 BIGINTA large integer
 DECIMALA fixed-point number
 FLOATA single-precision floating point number
 DOUBLEA double-precision floating point number
 BITA bit field

MySQL Boolean data type

MySQL does not have the built-in  BOOLEANor BOOL data type. To represent Boolean values, MySQL uses the smallest integer type which isTINYINT(1). In other words, BOOLEAN and BOOL are synonyms for TINYINT(1).

MySQL String data types

In MySQL, a string can hold anything from plain text to binary data such as images or files. Strings can be compared and searched based on pattern matching by using the LIKE operator, regular expression, and full-text search.

The following table shows the string data types in MySQL:

String TypesDescription
 CHARA fixed-length nonbinary (character) string
 VARCHARA variable-length non-binary string
 BINARYA fixed-length binary string
 VARBINARYA variable-length binary string
 TINYBLOBA very small BLOB (binary large object)
 BLOBA small BLOB
 MEDIUMBLOBA medium-sized BLOB
 LONGBLOBA large BLOB
 TINYTEXTA very small non-binary string
 TEXTA small non-binary string
 MEDIUMTEXTA medium-sized non-binary string
 LONGTEXTA large non-binary string
 ENUMAn enumeration; each column value may be assigned one enumeration member
 SETA set; each column value may be assigned zero or more SET members

MySQL date and time data types

MySQL provides types for date and time as well as the combination of date and time. In addition, MySQL supports timestamp data type for tracking the changes in a row of a table. If you just want to store the year without date and month, you can use the YEAR data type.

The following table illustrates the MySQL date and time data types:

Date and Time TypesDescription
 DATEA date value in CCYY-MM-DD format
 TIMEA time value in hh:mm:ss format
 DATETIMEA date and time value inCCYY-MM-DD hh:mm:ssformat
 TIMESTAMPA timestamp value in CCYY-MM-DD hh:mm:ss format
 YEARA year value in CCYY or YY format

MySQL spatial data types

MySQL supports many spatial data types that contain various kinds of geometrical and geographical values as shown in the following table:

Spatial Data TypesDescription
 GEOMETRYA spatial value of any type
 POINTA point (a pair of X-Y coordinates)
 LINESTRINGA curve (one or more POINT values)
 POLYGONA polygon
 GEOMETRYCOLLECTIONA collection of GEOMETRYvalues
 MULTILINESTRINGA collection of LINESTRINGvalues
 MULTIPOINTA collection of POINTvalues
 MULTIPOLYGONA collection of POLYGONvalues

JSON data type

MySQL supported a native JSON data type since version 5.7.8 that allows you to store and manage JSON documents more efficiently. The native JSON data type provides automatic validation of JSON documents and optimal storage format.

In this tutorial, you have learned various MySQL data types that help you determine which data type you should use for columns when you create tables.

转载于:https://www.cnblogs.com/zhuntidaoren/p/9523342.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值