What is the difference between MySQL int (1) and tinyint (1)?

Source: Internet
Author: User

Http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/08/25/2153016.html

What is the difference between MySQL int (1) tinyint (1)?
I have specified the field length, does the type still make sense? The reply:mysql in int (1) and tinyint (1) only specify the display length and do not represent the storage length, only the field designation Zerofill is useful
such as int (3), if the actual value is 2, if the column specifies Zerofill, the query result is 002, the left is filled with zeros. tinyint[(M)] [UNSIGNED] [Zerofill]

A very small integer. The signed range is-128 to 127. The unsigned range is 0 to 255.

int[(M)] [UNSIGNED] [Zerofill]

A normal-size Integer. The signed range is-2147483648 to 2147483647. The unsigned range is 0 to 4294967295.


The limit of the digits is basically meaningless.

Mysql> CREATE TABLE Testint (id int (1), col2 tinyint (1));
Query OK, 0 rows affected (0.06 sec)

mysql> INSERT into Testint values (256, 257);
Query OK, 1 row affected, 1 warning (0.03 sec)

Mysql> select * from Testint;
+------+------+
| ID | col2 |
+------+------+
| 256 | 127 |
+------+------+
1 row in Set (0.02 sec)

mysql> INSERT into Testint values (336, 257);
Query OK, 1 row affected, 1 Warning (0.02 sec)

Mysql> select * from Testint;
+------+------+
| ID | col2 |
+------+------+
| 256 | 127 |
| 336 | 127 |
+------+------+
2 rows in Set (0.00 sec)

mysql> INSERT into Testint values (336, 255);
Query OK, 1 row affected, 1 warning (0.03 sec)

Mysql> select * from Testint;
+------+------+
| ID | col2 |
+------+------+
| 256 | 127 |
| 336 | 127 |
| 336 | 127 |
+------+------+
3 Rows in Set (0.00 sec)

Mysql>

Take a look at the warning tips above ....
----------------------------MySQL true, what data type should be used for such data? Reply:tinyint (1)

What is the difference between MySQL int (1) and tinyint (1)?

Related Article

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.