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