Database Design for AI Coders
A database is just a collection of linked spreadsheets that your app uses to remember things. Let's break it down in plain English. Use our Database Planner to map out your tables visually.
In this chapter
- What a database is (think: linked spreadsheets)
- Tables, rows, and relationships explained simply
- Which database to pick for your first project
- How to ask your AI tool to design and set up your database
The Big Picture
Imagine a Google Sheets file with multiple tabs. Each tab holds different information: one for users, one for blog posts, one for comments. A database works the same way, except it's built to handle thousands (or millions) of entries without slowing down.
Key Concepts in Plain English
How Spreadsheets Link Together
The magic of databases is that spreadsheets can reference each other. Here are the three ways they connect.
One entry connects to exactly one entry in another spreadsheet.
One user has one profile. One profile belongs to one user.
Real-world analogy: Your driver's license links to exactly one person.
βSet up a database where each user has one profile with bio, avatar, and social links.β
One entry connects to many entries in another spreadsheet. This is the most common type.
One author writes many blog posts. Each blog post has one author.
Real-world analogy: One teacher has many students in their class.
βSet up a database where users can write many blog posts. Each post belongs to one user.β
Entries on both sides can connect to many entries on the other side. Needs a helper spreadsheet in between.
A blog post can have many tags. A tag can be on many posts.
Real-world analogy: Students take many classes. Each class has many students.
βSet up a database for blog posts and tags where each post can have multiple tags and each tag can be on multiple posts.β
What Kind of Information Can You Store?
When you tell your AI to create a database, it needs to know what kind of information goes in each column. Here are the everyday types.
Example Database Blueprints
Here's what the spreadsheet setup looks like for common apps. You can tell your AI tool to create any of these.
Who writes and comments: their name, email, profile photo, and when they joined Posts
Each blog post: title, the content, who wrote it, and when it was published Comments
Reader feedback: the comment text, who wrote it, which post it's on, and when Tags
Categories like "Travel" or "Food" that can be attached to posts
Shoppers: their name, email, and shipping address Products
What you sell: name, description, price, photo, and how many are in stock Orders
Each purchase: who bought it, the total cost, order status, and date Order Items
The specific products in each order: which product, how many, and the price paid Reviews
Customer feedback: star rating, review text, who wrote it, and which product
The company or team: name, plan level, and when they signed up Users
Team members: name, email, which organization they belong to, and their role Projects
Each project: name, which organization it belongs to, and who created it Tasks
Things to do: title, status (to-do, doing, done), which project, and who it's assigned to
People on the platform: username, display name, bio, and profile photo Posts
What people share: the text or image, who posted it, and when Likes
Who liked what: links a user to a post they liked Follows
Who follows whom: links one user to another user they follow Comments
Replies to posts: the comment text, who wrote it, and which post it's on
Prompts to Tell Your AI Tool
Copy and paste these into Claude Code, Cursor, Bolt, or whatever AI tool you use. Replace the words in [brackets] with your own details.
βSet up a database for a [blog / online store / booking app] with tables for [users, posts, comments] and connect them with the right relationships.β
βAdd a new table called [Reviews] to my database. Each review should store the text, a star rating (1-5), which user wrote it, and which product it's for.β
βConnect my [Posts] table to my [Users] table so that each post belongs to one user, and one user can have many posts.β
βI'm building a [recipe sharing app]. Design the complete database with all the tables I'll need, explain what each table stores, and set up the connections between them.β
βExplain the database you just created in simple terms. What tables are there, what does each one store, and how are they connected?β
Database Platforms
These are services that host your database in the cloud. You don't need to install anything: just sign up and your AI tool can connect to them. Most also include authentication so users can log in.
Tools That Help Your AI Connect to the Database
Your app needs a "bridge" to talk to the database. These tools act as translators: your AI writes app code on one side, and the tool converts it into database instructions on the other. You don't need to understand how they work; just tell your AI which one to use. Learn more about how this fits together in our backend guide.
Prompt This
Copy-paste these prompts into your AI tool to apply what you just learned.
βDesign a database schema for my [type of app]. I need to store [data types]. Show me the tables, columns, and relationships between them.β
βCreate Supabase tables for my project: [describe your app]. Include proper data types, foreign keys, and row-level security so users can only access their own data.β
βAdd a new [reviews/orders/bookings] table to my existing database. Connect it to my [users/products] table and explain the relationship.β
Frequently Asked Questions
Do I need to learn SQL or any database language?
No! Your AI tool writes all the database code for you. You just need to understand the concepts on this page so you can describe what you want. Say things like "I need a Users table connected to a Posts table" and your AI handles the rest.
What's the difference between SQL and NoSQL?
SQL databases are like structured spreadsheets with strict columns: every entry follows the same format. NoSQL databases are more flexible, like folders where each file can have different information. For most AI coding projects, SQL databases (like Supabase or Neon) are the easier choice because AI tools work better with them.
How do I know what tables my app needs?
Think about the "things" in your app. A blog has users, posts, and comments. An online store has users, products, orders, and reviews. Each "thing" gets its own table. When in doubt, tell your AI tool what your app does and ask it to design the database for you.
Can I change my database after I've started building?
Yes! You can always add new spreadsheets, add new columns, or change how things are connected. Just tell your AI tool: "Add a 'phone number' column to my Users table" and it will handle the change for you.
Where does my database actually live?
On a server in the cloud, managed by a platform like Supabase or Neon. You sign up, get a connection address (like a web link), and your AI tool uses that address to read and write data. You don't need to install anything on your computer.
Is my data safe?
The platforms listed above all handle security, backups, and encryption for you. For extra safety, tell your AI: "Make sure users can only see and edit their own data, not anyone else's." This keeps everyone's information private.