A3.2.3

Outline the different data types used in relational databases

Common relational database data types can be grouped into: string data types numeric data types date/time data types

2 min read354 words
  • Common relational database data types can be grouped into:
    • string data types
    • numeric data types
    • date/time data types

String data types

  • CHAR
    • fixed length
    • the length is defined explicitly, for example CHAR(7)
    • if the inserted value is shorter, spaces may be used to pad it
    • suitable for fixed-length values such as:
      • IDs
      • passwords
      • country codes
      • status flags
  • VARCHAR
    • variable length
    • suitable for:
      • names
      • emails
      • descriptions
  • TEXT
    • used for longer text such as:
      • blog posts
      • articles
      • comments
      • product reviews
  • MEDIUMTEXT
    • used for larger text such as:
      • long documentation
      • large JSON data
      • novels or books
  • LONGTEXT
    • used for extremely large text such as:
      • large archives
      • very large documentation
      • full codebases
  • ENUM
    • one value must be chosen from a predefined list
    • suitable for:
      • status fields
      • user roles
      • categories with exactly one allowed choice
  • SET
    • zero or more values can be chosen from a predefined list
    • suitable for:
      • user interests
      • multiple skills
      • multiple tags or categories

Numeric data types

  • BIT
    • stores bit-field values where each bit is 0 or 1
    • suitable for:
      • boolean values
      • on/off states
      • permission flags
  • BOOL / BOOLEAN
    • stores true/false style values
    • suitable for:
      • toggle settings
      • status indicators
  • INT
    • stores whole numbers
    • suitable for:
      • primary keys
      • foreign keys
      • counts
      • quantities
  • FLOAT
    • stores approximate decimal numbers
    • suitable when exact precision is less important
  • DECIMAL(a,b)
    • stores exact decimal numbers with fixed precision
    • a is the total number of digits
    • b is the number of digits after the decimal point
    • suitable for:
      • money
      • measured values where exact precision matters

Date/time data types

  • DATE
    • stores a calendar date
  • TIME
    • stores a time
  • DATETIME / TIMESTAMP
    • stores both date and time

Start typing to search all published objectives.