INT, BIGINT, SMALLINT, and TINYINT
All four store whole numbers without decimal places. The main differences are their range and storage size.
| Data type | Storage | Minimum value | Maximum value |
|---|---|---|---|
TINYINT |
1 byte | 0 | 255 |
SMALLINT |
2 bytes | -32,768 | 32,767 |
INT |
4 bytes | -2,147,483,648 | 2,147,483,647 |
BIGINT |
8 bytes | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
In SQL Server,
TINYINTdoes not support negative values.
Examples and uses
CREATE TABLE Employees
(
EmployeeId INT, -- Normal identifier
Age TINYINT, -- 0 to 255
DepartmentId SMALLINT, -- Small range of IDs
TotalViews BIGINT -- Very large count
);
TINYINT
Suitable for very small non-negative numbers:
Age TINYINT
Rating TINYINT
MonthNumber TINYINT
SMALLINT
Suitable when the value can exceed 255 but remains relatively small:
YearNumber SMALLINT
Quantity SMALLINT
INT
The most commonly used integer type:
EmployeeId INT
OrderId INT
Quantity INT
It is generally the default choice unless the business range requires a smaller or larger type.
BIGINT
Suitable for extremely large values:
TransactionId BIGINT
TotalPageViews BIGINT
LargeSequenceId BIGINT
In C#, SQL Server BIGINT maps to long.
Why does the correct size matter?
Choosing the smallest suitable type can reduce:
-
Table storage
-
Index size
-
Memory usage
-
Disk reads
-
Network transfer
However, do not choose a smaller type if the value may exceed its range. Changing a primary key from INT to BIGINT later can be difficult because related foreign keys and indexes must also be changed.
Identity example
CREATE TABLE Orders
(
OrderId BIGINT IDENTITY(1,1) PRIMARY KEY,
Quantity SMALLINT
);
IDENTITY automatically generates values, but the column is still limited by its chosen data type.
Key interview points
-
All four types store exact whole numbers.
-
Their main differences are range and storage size.
-
TINYINTis unsigned in SQL Server:0–255. -
INTis the usual general-purpose choice. -
Use
BIGINTonly when values may exceed theINTrange. -
Primary and foreign-key columns should use the same data type.
-
Larger key types increase table and index storage.
-
Integer overflow occurs when a value exceeds the type’s supported range.
-
They do not store decimal values; use
DECIMALwhen a fractional part is required.