EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

MySQL BigInt

By Payal UdhaniPayal Udhani

Home » Data Science » Data Science Tutorials » MySQL Tutorial » MySQL BigInt

MySQL BigInt

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 certain attributes related to BIGINT datatype like signed, unsigned, auto_increment, ZEROFILL, and display width. We will also discuss where and in which scenarios the BIGINT data type is mostly used.

Range and storage space for BigInt Datatype in MySQL

BIGINT datatype is the extension of the standard SQL integer type. Each integral datatype of MySQL can be declared either signed or unsigned. Signed data types specify that the negative integral values can also be stored in that column while unsigned always contains the positive integer values. By default, the datatype of any integral nature in MySQL is considered as a signed data type. The same goes with 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 the maximum value is -9223372036854775808 to 9223372036854775807 that includes almost 20 characters! while for unsigned BIGINT datatype, it is 0 to 18446744073709551615.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Usage of BigInt Datatype

This data type is most commonly used to store the integral value that will be too huge and big. Another usage of BIGINT datatypes is used to declare the primary key of the table that will store the autoincremented value and this table will contain a lot many records even more that the range of INT i.e 4294967295 and you are sure that the range of the value stored in this column will not exceed the range of the BIGINT data type. 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 that will contain the column as the BIGINT data type that will be the primary key and one more column that will be of BIGINT datatype but will not be a primary key. For example, we will create a table named subjects inside the educba database that exists on my database server. For this firstly, We will have to use educba database for which we will execute the following query –

use educba;

that will give following output –

MySQL BigInt 1

Further, we will create the table named subjects that will contain subject_id as the primary key column of BIGINT datatype and one more unsigned BIGINT column named pages wing the following query –

CREATE TABLE subjects (
subject_id BIGINT AUTO_INCREMENT PRIMARY KEY,
description VARCHAR(255),
pages BIGINT UNSIGNED
);

that gives the following output –

MySQL BigInt 2

Whenever a null or zero value is put in the auto_increment column then the sequence maintained for it automatically inserts the value incremented by 1 from the last maximum value inserted. It begins by inserting 1 value. In case, if a non-null and non-zero value is inserted in auto_increment value then that value is accepted and inserted in that column and the value of the sequence is set to that value +1 for further reference.

Let us insert some values in the table subjects using the following query –

INSERT INTO
subjects(description,pages)
VALUES
('MySQL',13600),
('Angular',20000),
('Java',96560);

that gives the following output –

MySQL BigInt 3

Let us check the inserted records by firing the command –

select * from subjects;

that gives following output –

MySQL BigInt 3

We can see that the subject_id column has got the default autoincremented values as 1,2 and 3. Let us insert one record mentioning the subject_id column value as follows –

INSERT INTO
subjects(subject_id,description,pages)
VALUES
(9223372036854775806,'Maven',156);

that gives following output –

MySQL BigInt 4

Let us check records of subjects table by using the same select query that gives the following output –

select * from subjects;

MySQL BigInt 5

We can see that 9223372036854775806 value is inserted into the subject_id column. Now, when we enter the record without mentioning the subject_id value, it will consider 9223372036854775807 as its next value as the sequence is set to that value after inserting 9223372036854775806 valued columns of subject_id. Executing the following command –

INSERT INTO
subjects(description,pages)
VALUES
('Hibernate',99);

gives following output –

MySQL BigInt 6

And after selecting the records of the table, it shows the following content –

select * from subjects;

MySQL BigInt 7

After inserting the record in the subjects table without subject_id specification such as following –

INSERT INTO subjects(description,pages) VALUES ('javascipt',105);

gives the error saying the 9223372036854775807 id is duplicated because the range f the BIGINT datatype of signed type by default exceeds and the output is as follows –

Popular Course in this category
MS SQL Training (13 Courses, 11+ Projects)13 Online Courses | 11 Hands-on Projects | 62+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,653 ratings)
Course Price

View Course

Related Courses
Oracle Training (14 Courses, 8+ Projects)PL SQL Training (4 Courses, 2+ Projects)

output

Let us see what happens if we specify the value of pages column of unsigned BIGINT type greater than 9223372036854775807 say 10223372036854775807 using the following insert query –

INSERT INTO
subjects(subject_id,description,pages)
VALUES
(4,'Typescript',10223372036854775807);

that gives following output –

output 1

and works completely fine because the range of unsigned BIGINT is 255 while of signed is 127.

After selecting the records, we see the following output –

select * from subjects;

output 2

Display width and ZEROFILL attribute –

Mysql allows specifying the display width of the column by specifying the display width in the data type followed by the () brackets inside which the integral value of the width can be specified. This does not tell about the storage size instead it stands for the format that should be used for displaying the values. When the ZEROFILL attribute is used for the column then all the blank spaces in the format specified by the display width are filled with the zeroes and the number is displayed. For example, if we alter the pages column of subjects table to ZEROFILL attribute and specify the display width as 20 using the following command –

ALTER TABLE subjects MODIFY COLUMN pages BIGINT(20) ZEROFILL;

that gives the following output –

output 3

By default when a column is assigned the ZEROFILL property it is automatically considered as the unsigned column. Let us now select the records of the subject table and observe the pages column values display format that should be 20-digit format with blank spaces replaced with 0.

The select query gives the following output –

select * from subjects;

output 4

Conclusion

The BIGINT data type is most often used to store the integral value that will be too huge and big. It can be assigned AUTO_INCREMENT, ZEROFILL attributes and its display width can be specified by using () brackets.

Recommended Articles

This is a guide to MySQL BigInt. Here we discuss Introduction, Usage of BigInt Datatype, and Examples with code implementation. You can also go through our other related articles to learn more –

  1. MySQL having
  2. MySQL BLOB
  3. MySQL encode()
  4. MySQL today()

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
MySQL Tutorial
  • Functions
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL count()
    • MIN() in MySQL
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • TRUNCATE TABLE MySQL
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL 
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT 
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL COALESCE
    • MySQL Cluster
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Basic
    • Introduction to MySQL
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • How To Install MySQL
    • MySQL OpenSource
    • MySQL Commands
    • Views in MySQL
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Advanced
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL UUID
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL Transaction
    • MySQL sort_buffer_size
    • MySQL Sync
    • MySQL Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
  • Interview Questions
    • MySQL Interview Questions

Related Courses

MS SQL Certification Courses

Oracle Certification Courses

PL/SQL Certification Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - MS SQL Certification Courses Learn More