Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

ตรวจสอบว่า BIGINT เป็น SIGNED หรือ UNSIGNED ใน MySQL

ค่าเริ่มต้นของ BIGINT คือ SIGNED ต้องระบุ UNSIGNED ตรงๆ ถ้าต้องการ

ตัวอย่าง

mysql> create table DemoTable (
    Number bigint,           -- signed
    Number2 bigint unsigned  -- unsigned
);
Query OK, 0 rows affected (1.08 sec)

ทดสอบช่วงค่า

mysql> insert into DemoTable values(18446744073709551615, 18446744073709551615);
ERROR 1264 (22003): Out of range value for column 'Number' at row 1
mysql> insert into DemoTable values(9223372036854775807, 18446744073709551615);
Query OK, 1 row affected (0.28 sec)

ผลลัพธ์

mysql> select * from DemoTable;
+---------------------+----------------------+
| Number              | Number2              |
+---------------------+----------------------+
| 9223372036854775807 | 18446744073709551615 |
+---------------------+----------------------+

BIGINT SIGNED: -9223372036854775808 ถึง 9223372036854775807
BIGINT UNSIGNED: 0 ถึง 18446744073709551615