CodeBlanks Logo Icon CodeBlanks

Integer types

Learn INT, SMALLINT, BIGINT integer types.

Integer types

SQL uses INT, SMALLINT and BIGINT for whole numbers. They differ in range and storage size.

CREATE TABLE products (
  id INT,
  stock SMALLINT,
  views BIGINT
);

INT for id, SMALLINT for small stock, BIGINT for large counts.

The table products is created.

Integer types — details

SMALLINT ranges from -32768 to 32767 and takes 2 bytes. INT gives about 2 billion range and takes 4 bytes. BIGINT is for very large numbers and takes 8 bytes.

Practice Integer types

Create products with id INT and stock SMALLINT columns.

Starter code

query.sql
-- create table
CREATE TABLE products

Sample solution

query.sql
CREATE TABLE products (
  id INT,
  stock SMALLINT
)

Expected output

Tablo oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which integer type has the largest range?

  • TINYINT
  • INT
  • SMALLINT
  • BIGINT Correct answer

Explanation: BIGINT gives the widest range.

2 Integer type

Question
CREATE TABLE t (id ____);
Answer
CREATE TABLE t (id INT);

Explanation: INT stores whole numbers; it suits counters such as id.

3 Integer types: match the terms

Term Meaning
INT integer
SMALLINT small integer
BIGINT big integer
DECIMAL decimal

All lessons in Beginner