Suggest suitable basic data types

📚 Databases: Basic Data Types

What is a Data Type?

A data type tells the database how to store and interpret a value. Think of it as a label on a box: it tells you what kind of items you can put inside.

  • Integer: Whole numbers, no decimals.
  • Real: Numbers that can have a fractional part.
  • String: Sequences of characters (letters, numbers, symbols).
  • Boolean: Only two values: true or false.
  • Date / Time: Represent calendar dates and clock times.

Analogies & Examples

  1. Integer: Imagine counting apples in a basket. You can only have whole apples: 0, 1, 2, … $n \in \mathbb{Z}$
  2. Real: Measuring the length of a table in metres. You might have 1.75 m, 3.2 m, etc.
  3. String: A sentence in a book. “Hello, world!” is a string of 13 characters.
  4. Boolean: A light switch: true (on) or false (off).
  5. Date / Time: The date 2024‑04‑26 or the time 14:30:00.

Choosing the Right Data Type

When designing a database, pick the type that best matches the data you want to store:

  • Use Integer for counts, IDs, and any whole number.
  • Use Real for measurements, prices, or any value that may have a fraction.
  • Use String for names, addresses, or any text.
  • Use Boolean for yes/no questions, flags, or status indicators.
  • Use Date / Time for dates, times, or timestamps.
Data Type Typical Use Example Value Exam Tip
Integer Counts, IDs, scores 42 Remember: no decimal point.
Real Measurements, prices 19.99 Use FLOAT or DOUBLE for higher precision.
String Names, addresses, text “Alice Smith” Choose VARCHAR with a max length.
Boolean Yes/No, true/false flags true Use BIT(1) or BOOLEAN.
Date / Time Dates, timestamps 2024‑04‑26 Use DATE or DATETIME as needed.

📌 Examination Tips

  • When a question asks for a “whole number”, choose Integer.
  • If the data can have a decimal part, pick Real (FLOAT or DOUBLE).
  • For text up to 255 characters, VARCHAR(255) is usually safe.
  • Boolean values are often stored as BIT(1) or BOOLEAN.
  • Dates are stored in the format YYYY‑MM‑DD; times use HH:MM:SS.

Revision

Log in to practice.

0 views 0 suggestions