Module 52: Database Structure

Lesson 2 of 5 · 15–25 minutes

Data types

🏠The everyday picture

Containers in a kitchen: a bottle for oil, a jar for rice, a tray for eggs. Putting rice in the egg tray "works", but causes trouble later.

📘What it really is

Common SQL types (names vary slightly between databases; these are PostgreSQL's):

SQLite is more relaxed: it has only a few storage types and, by default, will store text in an integer column. Declaring a table as STRICT makes it enforce types (Module 59).

🖱️Try it

In DB Browser, create a payments table with: id, customer_id, amount_paise (integer), method (text), paid_at (text holding an ISO timestamp, since SQLite has no timestamp type) and note. Create it with CREATE TABLE ... STRICT in the Execute SQL tab, and try inserting text into amount_paise.

✅Quick check

Should a phone number be stored as a number or text?

Show the answer

Text. It's an identifier; arithmetic is meaningless, and +91 or leading zeros must be kept.

Why store timestamps in UTC?

Show the answer

One consistent reference avoids confusion across time zones and daylight-saving changes; convert only for display.

← PreviousTables, rows and columns
ProLearners Assist