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

The SMALLINT data type is an integer value from -32,768 to 32,767.

SMALLINT uses 2 bytes of storage.

Example

#

A table with a SMALLINT column.

CREATE TABLE DemoTable  
( 
  Id INT IDENTITY, 
  BuildingName VARCHAR(100),
  Age SMALLINT
);
GO  

INSERT INTO DemoTable VALUES ('Ancestral Puebloan dwellings', 173);  
INSERT INTO DemoTable VALUES ('Deane Winthrop House', 346);  
INSERT INTO DemoTable VALUES ('White Horse Tavern', 369);
INSERT INTO DemoTable VALUES ('Old Powder House', 274); 
INSERT INTO DemoTable VALUES ('Chaco Canyon', NULL); 
GO  

SELECT * FROM DemoTable;
GO

DROP TABLE DemoTable;
GO
Result:  5 records
Id BuildingName Age
1 Ancestral Puebloan dwellings 173
2 Deane Winthrop House 346
3 White Horse Tavern 369
4 Old Powder House 274
5 Chaco Canyon NULL

More Examples

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