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.
|
-2,147,483,648 to 2,147,483,647
| 4 bytes
|
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
| 8 bytes
|
-32,768 to 32,767
| 2 bytes
|
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.
Similar Reads
SQL Server DECIMAL Data Type
In SQL Server, when you need numbers to be super precise, like in financial calculations, you use the DECIMAL data type. It's like a special box for storing exact numbers and no rounding off! In simpler terms, decimal is SQL Server's way of saying, "I don't mess around with numbers." It's the go-to
4 min read
SQL Server BIT Data Type
The BIT data type is used to store boolean values like 0, 1, or NULL. The SQL server doesn't have the data Boolean instead it has the data type BIT which has which stores the boolean value. The BIT data type is advantageous in terms of space optimization since each BIT data type takes on only 1 bit
3 min read
PostgreSQL - INTEGER Data Type
In PostgreSQL, the INTEGER data type is widely used for storing numerical data efficiently. It is a 4-byte data type that allows us to store whole numbers within a specified range, making it ideal for various use cases like population counts, active user statistics, and more. In this article, we wil
4 min read
CREATE TABLE in SQL Server
SQL Server provides a variety of data management tools such as querying, indexing, and transaction processing. It supports multiple programming languages and platforms, making it a versatile RDBMS for various applications. With its robust features and reliability, SQL Server is a popular choice for
4 min read
PostgreSQL - Date Data Type
PostgreSQL offers powerful DATE data type and date functions to efficiently handle date and time information. PostgreSQL DATE data type allows for storing and manipulating calendar dates while its robust set of date functions enables users to perform operations like date arithmetic and formatting. I
4 min read
PostgreSQL - Data Types
PostgreSQL is a robust open-source relational database management system that supports a wide variety of data types. These data types are essential for defining the nature of the data stored in a database column, affecting storage, access, and manipulation. In this article, We will learn about the P
5 min read
PostgreSQL - NUMERIC Data Type
In PostgreSQL, the NUMERIC data type is designed for high-precision number storage by making it ideal for financial and scientific applications where accuracy is critical. It supports a large number of digits both before and after the decimal point, minimizing rounding errors. Understanding the nuan
5 min read
SQL Data Types
SQL Data Types are very important in relational databases. It ensures that data is stored efficiently and accurately. Data types define the type of value a column can hold, such as numbers, text, or dates. Understanding SQL Data Types is critical for database administrators, developers, and data ana
6 min read
PostgreSQL - BIGINT Integer Data Type
PostgreSQL is a powerful open-source relational database management system that offers various integer data types to suit different needs. One of these is the BIGINT data type, designed for storing very large integers. In this article, we will explain the details of the BIGINT data type in PostgreSQ
3 min read
PL/ SQL Data Types
PL/SQL (Procedural Language/Structured Query Language) is a procedural extension language for SQL used specifically for the Oracle database to ease the management of data and the flow of operations. A core feature of PL/SQL is its diverse set of data types, designed to handle everything from simple
6 min read