Databases
How do I design a database?
Start with the work, not the database product
A database stores information so an application can find and update it consistently. Before choosing PostgreSQL, MySQL, SQLite, MongoDB, or a hosted service, write down the real questions the system must answer: which orders are waiting, who owns each task, or when a booking begins.
Those questions reveal the facts worth storing and how long the information needs to remain available. A class project, a public directory, and a payment system have different needs for access, reliability, privacy, and backups.
Turn real things into a data model
List the important things your system needs to remember, such as customers, orders, and products. For each, identify the facts that describe it and a stable identifier that distinguishes one record from another.
Then describe the relationships in plain language. One customer can place many orders; each order can contain several products. In a relational database, separate tables represent these different entities, while keys connect related rows.
Do not create a table for every screen or store the same fact in several places without a reason. Repetition leads to update mistakes. A normalized relational design stores each fact in an appropriate place and relates it through keys.
Choose a database for the requirements
A relational database is a strong fit when the data has clear relationships and the application needs structured queries and transactions. A document database can suit records with flexible, nested shapes, but flexibility does not remove the need to decide how data will be queried and validated.
For a small single-device application, a local database may be enough. A shared web application usually needs a managed or server-based database, access controls, backups, and a migration plan. Estimate expected data, concurrent users, operational skills, and cost before selecting a service.
Protect data and test the model
Use constraints to prevent invalid states where the database can enforce them: required fields, unique values, valid references, and sensible checks. Add indexes for common lookup and join patterns after you understand the queries; unnecessary indexes consume storage and slow writes.
Only collect information the product needs. Restrict access by role, use secure connections and managed secrets, and make backups that you have actually tested restoring. Personal information may have legal requirements that depend on where your users live and where you operate.
Try the model with realistic examples, including awkward cases such as cancellations, duplicate submissions, missing optional information, and changes to a customer's details. If the model makes a normal task confusing, revise it before building more screens.
A beginner's first database design
For a basic booking tool, begin with customers, services, and appointments. Give each record an ID, store only the details needed to complete the booking, and define which customer and service belong to each appointment. Decide how a booking changes when someone cancels or reschedules.
Draw the entities and relationships, write down a few real questions the app must answer, then test those questions against the proposed tables. This small exercise catches missing relationships earlier than starting with a framework or schema generator.
Sources and further reading
Frequently asked questions
How do I design a database?
Name the things you must remember and how they relate. Then make tables. The product, such as SQLite or PostgreSQL, comes after that model.
What is a table?
A list of one kind of thing, with one row per item and columns for the facts about it.
What is a primary key?
A value that identifies one row and no other. A name is a weak key because two people can share it.
Should I start with a spreadsheet?
Yes for a short list you edit alone. Use a database when many people edit the same records or the same fact would be copied.
Can I practice with real names?
Prefer fake data. If you must use real records, do not upload them to a public place, and follow the privacy rules where you live.
Which database should a beginner install?
SQLite is enough to learn on your own computer. The model matters more than the brand.