SQL Data Types

Choose the right type for each column.

✍️ 3 exercises + code challenge in this lesson

Every column has a data type. Common types (names vary slightly between databases):

  • Text: CHAR(n) fixed length, VARCHAR(n) variable length, TEXT long text.
  • Whole numbers: TINYINT, SMALLINT, INT, BIGINT.
  • Exact decimals: DECIMAL(10,2). Use it for money.
  • Approximate decimals: FLOAT, DOUBLE.
  • Dates: DATE, TIME, DATETIME, TIMESTAMP.
  • Boolean: BOOLEAN (stored as 0/1 in MySQL and SQLite).
  • Other: JSON, BLOB (binary), ENUM (MySQL).
Never store money in FLOAT: rounding errors add up. Use DECIMAL or store whole paisa as an integer.

Key Takeaways: SQL Data Types

Mastering SQL Data Types helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL Data Types Code Example

SQL
SELECT 0.1 + 0.2              AS FloatMaths,
       CAST(0.1 + 0.2 AS TEXT) AS AsText,
       typeof(42)             AS IntType,
       typeof(4.2)            AS RealType,
       typeof('42')           AS TextType,
       typeof(NULL)           AS NullType;
Free sign-in required · Google login available

SQL Data Types Practice Exercises

Check what you learned in “SQL Data Types”.

/ 3 solved
Fill in the blank

Use an exact type for money (MySQL).

Price (10, 2)
✓ Correct! Not quite. Try again.
Multiple choice

Why should money not be stored as FLOAT?

✓ Correct! Not quite. Try again.
Code challenge

Select typeof(12), typeof(1.5), typeof('x') in SQLite.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services