Updated June 1, 2023
Introduction to MySQL BigInt
BIGINT is the MySQL data type that can be assigned to the columns of the table in which we want to store the whole numbers, and we are aware that the range of the numbers that we will store in that column will be huge and not exceed the range of the BIGINT data type. In this article, we will learn about the BIGINT datatype of MySQL, its range and storage size, and also learn about specific attributes related to BIGINT datatypes like signed, unsigned, auto_increment, ZEROFILL, and display width. Additionally, we will explore the scenarios and use cases where the BIGINT data type is primarily utilized
Range and storage space for BigInt Datatype in MySQL
BIGINT datatype is the extension of the standard SQL integer type. MySQL allows the declaration of each integral data type as either signed or unsigned. Signed data types enable storage of both positive and negative integral values, while unsigned data types exclusively store positive integer values. By default, integral data types in MySQL are considered signed. The same goes for the BIGINT data type. By default, it is signed BIGINT in its functionality. It takes 8 bytes to store the value of the BIGINT data type. The range of the signed BIGINT datatype from minimum to maximum value is -9223372036854775808 to 9223372036854775807, which includes almost 20 characters! While for unsigned BIGINT datatype, it is 0 to 18446744073709551615.
Usage of BigInt Datatype
We commonly use the BIGINT data type to store large integral values. Another scenario for using BIGINT is declaring the primary key of a table to store auto-incremented values. This is especially valuable when the table is expected to contain a substantial number of records, surpassing the range of INT (4294967295). With BIGINT, you can ensure that the stored values in this column will not exceed the data type’s range. That means in case if your table is going to contain only too many records and you want to declare an integral column that will store the autoincremented whole numbers, then instead of using the MySQL INT or INTEGER data type, you will declare the datatype of the column as BIGINT.
Example
Let us create a table containing the column as the BIGINT data type that will be the primary key and one more column that will be of BIGINT datatype but not a primary key. For example, we will create a table named subjects inside the educba database on my server. For this, firstly, We will have to use the educba database, for which we will execute the following query –