BIGINT Data Type

The BIGINT data type stores whole numbers. It can store integer values from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.

Syntax

BIGINT

Description

BIGINT is an integer data type that stores non-decimal values. In SQL Server, it occupies 8 bytes of storage.

Range and Storage

  • Minimum Value: -9,223,372,036,854,775,808
  • Maximum Value: 9,223,372,036,854,775,807
  • Storage Size: 8 bytes

When to Use BIGINT

Use BIGINT when you need to store very large whole numbers that exceed the capacity of other integer types like INT or SMALLINT. For example:

  • Storing the number of rows in extremely large tables.
  • Representing financial values that can reach billions or trillions.
  • Storing system-wide identifiers or counters that may grow extensively.

Example Usage

Here's an example of declaring a BIGINT column and inserting a value:


CREATE TABLE OrderQuantities (
    OrderID INT PRIMARY KEY,
    TotalItems BIGINT
);

INSERT INTO OrderQuantities (OrderID, TotalItems)
VALUES (1, 15000000000); -- A large number of items
                

Comparison with Other Integer Types

Here's a brief comparison with other common integer types in SQL Server:

  • TINYINT: 0 to 255 (1 byte)
  • SMALLINT: -32,768 to 32,767 (2 bytes)
  • INT: -2,147,483,648 to 2,147,483,647 (4 bytes)
  • BIGINT: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8 bytes)
Important Note: Always choose the smallest data type that can adequately store your data to optimize storage space and performance. Using BIGINT unnecessarily can consume more memory and disk space.

See Also