Common data types are:
integers: tinyint, smallint, mediumint, int, bigint
Floating point number: float, double
Fixed-point number: decimal
String: char, varchar, tinytext, text, Mediumtext, Longtext
Date: Date, DateTime, timestamp, year, time
How to declare integers:
| Type |
How to declare |
| tinyint |
tinyint[(m)] [UNSIGNED] [Zerofill] M default is 4 |
| smallint |
smallint[(m)] [UNSIGNED] [Zerofill] M default is 6 |
| Mediumint |
mediumint[(m)] [UNSIGNED] [Zerofill] M default is 9 |
| Int |
int[(m)] [UNSIGNED] [Zerofill] M default is 11 |
| bigint |
bigint[(m)] [UNSIGNED] [Zerofill] M default is 20 |
Note: The m here represents not the exact length stored in the database, but the minimum number of display digits of the int, and the value will not take effect until the Zerofill is specified.
Mysql> CREATE table T (tint(3)); Query OK,0Rows Affected (0.02sec) MySQL> INSERT into T values ( One),(111),(1111); Query OK,3Rows Affected (0.00sec) Records:3Duplicates:0Warnings:0MySQL>Select*From t;+------+| T |+------+| One||111||1111|+------+3RowsinchSet (0.00sec) MySQL> ALTER TABLE t change t tint(3) Zerofill; Query OK,3Rows Affected (0.06sec) Records:3Duplicates:0Warnings:0MySQL>Select*From t;+------+| T |+------+|011||111||1111|+------+3RowsinchSet (0.00Sec
MySQL data type