Nombor 1 yang digunakan dalam kurungan adalah untuk paparan lebar sahaja. INT(1) dan TINYINT(1) tidak menjejaskan storan.
TINYINT menduduki 1 bait, yang bermaksud julatnya ialah -128 hingga +127, manakala int menduduki 4 baitnya ialah -2147483648 hingga +2147483647
# 🎜 paparan, mari kita cipta jadual -mysql> create table intAndTinyint −> ( −> FirstNumber int(1) zerofill, −> SecondNumber tinyint(1) zerofill −> ); Query OK, 0 rows affected (0.52 sec)
mysql> insert into intAndTinyint values(1,1); Query OK, 1 row affected (0.32 sec) mysql> insert into intAndTinyint values(12,12); Query OK, 1 row affected (0.26 sec) mysql> insert into intAndTinyint values(123,123); Query OK, 1 row affected (0.14 sec)
mysql> select *from intAndTinyint;
+-------------+--------------+ | FirstNumber | SecondNumber | +-------------+--------------+ | 1 | 1 | | 12 | 12 | | 123 | 123 | +-------------+--------------+ 3 rows in set (0.00 sec)
mysql> create table intVsIntAnyThingDemo −> ( −> Number1 int(11) unsigned zerofill, −> Number int(13) unsigned zerofill −> ); Query OK, 0 rows affected (1.17 sec)
mysql> insert into intVsIntAnyThingDemo values(12345,6789); Query OK, 1 row affected (0.44 sec) mysql> insert into intVsIntAnyThingDemo values(3,2); Query OK, 1 row affected (0.20 sec) mysql> insert into intVsIntAnyThingDemo values(12,89); Query OK, 1 row affected (0.15 sec) mysql> insert into intVsIntAnyThingDemo values(123,6789); Query OK, 1 row affected (0.17 sec) mysql> insert into intVsIntAnyThingDemo values(1234,6789); Query OK, 1 row affected (0.14 sec)
mysql> select *from intVsIntAnyThingDemo;
+-------------+---------------+ | Number1 | Number | +-------------+---------------+ | 00000012345 | 0000000006789 | | 00000000003 | 0000000000002 | | 00000000012 | 0000000000089 | | 00000000123 | 0000000006789 | | 00000001234 | 0000000006789 | +-------------+---------------+ 5 rows in set (0.00 sec)
Atas ialah kandungan terperinci Adakah terdapat perbezaan antara menggunakan INT(1) dan TINYINT(1) dalam MySQL?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!