Beginner Topic 17 of 51 Databases
Data Types in SQL
Column types like INT, VARCHAR and DATE.
How it works
SQL columns have types that define the allowed values, storage and operations. Common ones are INTEGER and BIGINT, DECIMAL or NUMERIC for exact numbers, FLOAT and DOUBLE for approximate ones, CHAR and VARCHAR and TEXT for strings, DATE, TIME and TIMESTAMP, BOOLEAN, BLOB for binary data, and JSON and UUID in many systems. Choosing the smallest suitable type saves space and speeds comparisons and indexes.
Step-by-step walkthrough
- INT stores whole numbers.
- DECIMAL stores exact numbers, perfect for money.
- VARCHAR stores variable length text.
- DATE and TIMESTAMP store times.
- Choosing the right type saves space and prevents invalid data.
Where it is used
Storing money as DECIMAL, dates as DATE or TIMESTAMP WITH TIME ZONE and flags as BOOLEAN gives correct sorting, arithmetic and validation.
Common pitfall
Using FLOAT for currency produces rounding errors. Storing numbers or dates as strings breaks sorting and comparisons. VARCHAR lengths and character sets matter for Unicode. Time zone handling is a frequent source of bugs, so store UTC. Implicit conversions can stop indexes from being used, so compare like with like.
Where it fits in the course
Data Types in SQL is topic 17 of 51 in Databases, rated Beginner. It follows Entity-Relationship Modeling. The next topic is Subqueries.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Data Types in SQL?
Where do people use Data Types in SQL?
What is the most common mistake with Data Types in SQL?
What should I learn before this topic?
How can I practice it?
Is Data Types in SQL hard to learn?
How long does it take to learn Data Types in SQL?
Which topics are related to Data Types in SQL?
What should I study after Data Types in SQL?
Related topics
- Entity-Relationship Modeling (Databases)
- Subqueries (Databases)
- Inner and Outer Joins (Databases)
- Views (Databases)
- Data Types (Programming Fundamentals)
- Algebraic Data Types (Languages & Compilers)
- Open Data and Licensing (Emerging & Frontier Topics)