Lesson 31 +10 XP

SQL Data Types

SQL Data Types

Every column has a data type that defines what kind of data it can hold.

Numeric types

TypeStores
intwhole numbers (e.g. -2, 0, 42)
decimal(p,s)exact decimals (p = total digits, s = decimals after point)
floatapproximate decimals
bigintvery large whole numbers

String types

TypeStores
char(n)fixed-length text (always n chars)
varchar(n)variable-length text up to n chars
textlong text

Date and time types

TypeStores
datedate only (YYYY-MM-DD)
timetime only (HH:MM:SS)
datetimedate and time

Other types

TypeStores
booleantrue or false
blobbinary data (images, files)

MySQL notes

  • MySQL also has TINYINT, MEDIUMINT, BIGINT.
  • TEXT, MEDIUMTEXT, LONGTEXT for longer text.
  • TIMESTAMP tracks date+time.

Why types matter

The type determines:

  • What values are allowed (text vs numbers).
  • How much space each row uses.
  • Which functions and comparisons work.

TL;DR

  • int for whole numbers, decimal for money.
  • varchar(n) for text up to n characters.
  • date/datetime for dates and times.
  • The right type keeps your data correct.