Data types in MySQL

Source: Internet
Author: User

The data type is used to specify a certain storage format, constraint, and valid range.
MySQL mainly includes: numeric type, string type, date and time type, etc.

1. Numeric Type:

1) Integer type:
tinyint, smallint, mediumint, int, bigint
An "Out of range" error prompt is prompted if an operation of type range is exceeded.

Note:
1.MYSQL Specifies the display width after the type name: for example: Int (5)
If the specified width is not displayed, the default is int (11).
2. Generally with Zerofill use, as the name implies, Zerofill is filled with "0" meaning, the number of digits in the space is not enough to fill with the character "0". Here are some examples of how to compare

(1) CREATE table T1, with Id1 and Id2 two fields, specifying their numeric widths as int and int (5) respectively.

(2) inserting the value 1 in ID1 and ID2, you can see that there is no exception to the format.

(3) Modify the field type of Id1 and Id2 respectively, add the Zerofill parameter:

Comparison example:

Note: (attribute)
1. All integer types have an optional attribute unsigned (unsigned). However, if a column is specified as Zerofill, MySQL automatically adds the Unisigned property to the column.

2. If the integer type is to be ordered in order and you want to mark it, use the attribute: auto_increment (used to produce a unique identifier or sequential value and only for the integer type, with a maximum of one auto_increment column in a table).
For any auto_increment that want to use the
column, which should be defined as not NULL and defined as PRIMARY key or defined as a UNIQUE key. For example, you can define a auto_increment column in any of the following ways:
CREATE TABLE AI (ID INT auto_increment not NULL PRIMARY KEY);
CREATE TABLE AI (id INT auto_increment not NULL, PRIMARY KEY (id));
CREATE TABLE AI (id INT auto_increment not NULL, UNIQUE (ID));

Data types in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.