BIGINT
BIGINT is a data type in SQL. It is used to store large numeric values that exceed the limits of other integer types. BIGINT typically accommodates numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. As the largest available numeric type, BIGINT is ideal for data entities with large numeric ranges. However, it should be implemented discerningly due to its substantial storage size requirement.
Example
CREATE TABLE Employees ( ID BIGINT, Name VARCHAR(100));
INSERT INTO Employees(ID, Name)VALUES (12345678901234, 'John Doe');Output
Query OK, 1 row affected (0.01 sec)Explanation
In the provided example, a table named ‘Employees’ is created with two columns: ID and Name. The ID column is declared with BIGINT data type to store large integer values. A new row has been inserted into this table with an ID value of 12345678901234, illustrating the use of BIGINT for large integers.
Example
CREATE TABLE Employees ( ID BIGINT, Name TEXT);
INSERT INTO Employees (ID, Name) VALUES (9223372036854775807, 'John Smith');Output
SELECT * FROM Employees;
ID | Name---------------------+------------- 9223372036854775807 | John SmithExplanation
The BIGINT datatype is used to store large numbers. It can store numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. In the example, we have created an Employees table with ID as a BIGINT and Name as TEXT. Then we inserted a row with ID as the maximum value a BIGINT can hold.
Example
CREATE TABLE Example( ID BIGINT, Name VARCHAR(50));
INSERT INTO Example(ID, Name) VALUES(9223372036854775807, 'ExampleName');SELECT * FROM Example;Output
ID | Name------------------------|-----------9223372036854775807 | ExampleNameExplanation
In this example, a table named Example is created with two columns: ID and Name. The ID column uses the BIGINT data type, which can store large integer numbers. A row is inserted into the Example table with the ID value is the maximum allowed for a BIGINT value (9223372036854775807), and a SELECT * query is executed to return all row(s) from the Example table.
Example
CREATE TABLE Employee ( ID BIGINT, Name VARCHAR2(100));
INSERT INTO Employee (ID, Name)VALUES (1234567890123456789, 'John Doe');
SELECT * FROM Employee;Output
ID | Name---------------------|-----------------1234567890123456789 | John DoeExplanation
In this example, a table Employee is created with two columns: ID of data type BIGINT and Name of data type VARCHAR2(100). One record is inserted with ID as 1234567890123456789 and Name as John Doe. The SELECT statement retrieves all the records from the Employee table.
Example
CREATE TABLE Employees ( ID BIGINT PRIMARY KEY, NAME TEXT NOT NULL, AGE INT NOT NULL, SALARY DEC NOT NULL);
INSERT INTO Employees (ID, NAME, AGE, SALARY)VALUES (12345678910, 'John Doe', 30, 50000);
SELECT * FROM Employees;Output
ID | NAME | AGE | SALARY------------- |--------- | --- | ------12345678910 | John Doe | 30 | 50000Explanation
In the CREATE TABLE statement, a table called Employees is generated and the ID column is declared to be of BIGINT type which is a large-sized integer. BIGINT is used when the data to be stored is expected to exceed the storage size of usual integer types. The table also includes NAME, AGE and SALARY columns of types TEXT, INT, and DEC respectively.
Then an INSERT INTO statement is used to insert values (‘John Doe’, 30, 50000) into the columns of Employees table where the ID is 12345678910, exhibiting the purpose of BIGINT type, capable of storing much larger numbers.
The SELECT * FROM Employees; statement extracts and shows all records from the Employees table, as seen in the output.