Dofactory.com
Dofactory.com
Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

SQL INT Data Type

The INT data type is an integer value from -2,147,483,648 to 2,147,483,647.

INT uses 4 bytes of storage.

INT is the most commonly used integer data type in SQL Server.

Example

#

A table with an INT column.

CREATE TABLE DemoTable  
( 
  Id INT IDENTITY, 
  CompanyName VARCHAR(100),
  Employees INT
);
GO  

INSERT INTO DemoTable VALUES ('Walmart', 2200000);  
INSERT INTO DemoTable VALUES ('Amazon', 1298000);  
INSERT INTO DemoTable VALUES ('Allied Universal', 800000);
INSERT INTO DemoTable VALUES ('FedEx Corporation', 650000); 
INSERT INTO DemoTable VALUES ('Home Depot', NULL); 
GO  

SELECT * FROM DemoTable;
GO

DROP TABLE DemoTable;
GO
Result:  5 records
Id CompanyName Employees
1 Walmart 2200000
2 Amazon 1298000
3 Allied Universal 800000
4 FedEx Corporation 650000
5 Home Depot NULL

More Examples

INT with ORDER ITEMS

ORDER
Id
OrderDate
OrderNumber
CustomerId
TotalAmount
PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
Problem: Find all line items for order # '542378'.
SELECT ProductName, I.UnitPrice, Quantity,
       I.UnitPrice * Quantity AS 'Total'
  FROM Product P
  JOIN OrderItem I ON P.Id = I.ProductId
  JOIN [Order] O ON I.OrderId = O.Id
 WHERE OrderNumber = '542378'
Result:  3 records
ProductName UnitPrice Quantity Total
Queso Cabrales 14.00 12 168.00
Singaporean Hokkien Fried Mee 9.80 10 98.00
Mozzarella di Giovanni 34.80 5 174.00

INT with OTHER INT DATA TYPES

Problem: List the maximum value of each integer data type.
CREATE TABLE DemoTable  
( 
  MyBigInt BIGINT,
  MyInt INT,
  MySmallInt SMALLINT,
  MyTinyInt TINYINT
);
GO  

INSERT INTO DemoTable VALUES (9223372036854775807, 2147483647, 32767, 255);  
GO  

SELECT * FROM DemoTable;
GO

DROP TABLE DemoTable;
GO
Result:  1 record
MyBigInt MyInt MySmallInt MyTinyInt
9223372036854775807 2147483647 32767 255

You may also like



Last updated on Dec 21, 2023

Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.