Open In App

SQL Server INT Data Type

Last Updated : 01 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In SQL Server, while creating a table column we give different data types to represent the type of values stored in the column. For numerical whole numbers, we give INT data type for a column in a table. In this article let us discuss the INT data type, how it is used, and the different INT data types available in SQL Server.

What is the INT data type?

In SQL Server, for storing integer or numeric values in a table column the INT data type is used. The INT data type can store whole numbers, which can be positive or negative. The value range of the INT data type is from -2,147,483,648 to 2,147,483,647. The memory storage size of the INT data type for a column is 4 bytes.

Uses of INT data type

The INT data type is used for any columns with numerical data like ID, Integer Values, or Currency values without decimals. The INT data type is also used to create a column with a Primary Key in a table.

Example of INT datatype:

Below is an example of the INT data type (Student_ID) used to create a table column:

CREATE TABLE [dbo].[Students](
[Student_ID] [int] NULL,
[Student_Name] [varchar](50) NOT NULL,
[Grade] [char](1) NULL
) ON [PRIMARY]
GO

Different INT data types

SQL Server supports 4 different integer value types such as INT, BIGINT, SMALLINT and TINYINT. The INT data type is the primary integer data type supported by SQL Server. When a database has large amount of data, the datatype really matters. So to save space it is best to use the smallest data type which should be sufficient to hold the values in the column. So for example to store a person’s age, the tinyint data type should be sufficient as the age value will be less than 200, and tinyint holds value between 0 to 255. But if we need to store values above 255 then, based on the largest possible value, the other data type should be used.

Below is the table of all INT data types and the range of values it will hold in the column.

Data Type

Data Range

Storage Size

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

SMALLINT

-32,768 to 32,767

2 bytes

TINYINT

0 to 255

1 byte

Example of different INT data types used to create a table:

CREATE TABLE DemoINTValTable  
(
DemoInt_Column INT,
,DemoBigInt_Column BIGINT,
DemoSmallInt_Column SMALLINT,
DemoTinyInt_Column TINYINT
);
GO

Below is the sample insert query with different INT values to the table:

INSERT INTO DemoINTValTable (
DemoInt_Column,
DemoBigInt_Column,
DemoSmallInt_Column,
DemoTinyInt_Column
)
VALUES
(
2147483647,
9223372036854775807,
32767,
255
);

Conclusion

In this article we have discussed about the INT data type in SQL Server and also other Integer data types available in SQL server which are used in creating table columns. Also the data ranges and storage size of each data type and their usage is explained with examples.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads