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 TINYINT Data Type

The TINYINT data type is an integer value from 0 to 255.

TINYINT is the smallest integer data type and only uses 1 byte of storage.

An example usage of TINYINT is a person's age since no person reaches the age of 255.

Example

#

A table with a TINYINT column.

CREATE TABLE DemoTable  
( 
  Id INT IDENTITY, 
  Name VARCHAR(100),
  Age TINYINT
);
GO  

INSERT INTO DemoTable VALUES ('Anna', 32);  
INSERT INTO DemoTable VALUES ('Carlos', 19); 
INSERT INTO DemoTable VALUES ('Marlon', 55);  
INSERT INTO DemoTable VALUES ('Kelly', 41);
INSERT INTO DemoTable VALUES ('Martha', NULL); 
GO  

SELECT * FROM DemoTable;
GO

DROP TABLE DemoTable;
GO
Result:  5 records
Id Name Age
1 Anna 32
2 Carlos 19
3 Marlon 55
4 Kelly 41
5 Martha NULL

More Examples

TINYINT 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.