What does an AI need to know to design a database?
An AI can design a database schema, but it needs to know which system it will run on, what goes into it and how you'll recognise a good result. Five details cover that: system, content, rules, size and the form you want the result in.
By Kasum BajramiUpdated
What does the AI need to know from you?
Which system and which technology?
Commands and data types differ between systems. If you don't say, the AI picks one, and your design may not run on yours.
What should be stored?
The things and how they relate, in plain words, for example books, members and loans. The tables come from that.
Which rules should the database enforce itself?
For example, that a book can only be on loan to one person at a time. A rule that isn't named ends up somewhere in the program later instead of in the database.
How big will it get?
A few hundred rows or millions, one user or many. The size decides how much effort is worth spending on indexes and partitioning.
What form do you want the result in?
A description of the tables, ready-to-run commands to create them, or both: that decides whether you can read the result or run it straight away.
What does that look like as a finished prompt?
Example
This is how the conversation could go. The example is written by hand, following the rules Finn uses for his questions, and doesn't come from a real conversation.
- The idea
- I need a database for a small club library.
- The question
- Which database system do you use? What should be stored, and which rules apply? Roughly how big will the library be? Do you want a table design, ready-made SQL commands or both?
- The reply
- PostgreSQL. Books, members and loans; a book is on loan to only one member at a time. A few hundred books. SQL commands with a short explanation.
The finished prompt
You are an experienced database developer. Design a relational database for the library of a small club.
System: PostgreSQL.
It stores books, members and loans. At any one time, a book is on loan to at most one member. There are a few hundred books.
Result: 1. A short description of the tables and how they relate. 2. The complete CREATE TABLE statements with primary keys, foreign keys and the rules the database enforces itself. 3. Two example queries: all books currently on loan and all overdue loans.
Rules: Use descriptive column names in lower case. Do not put real personal data in example data; use [name] and [email] instead. Do not make up requirements I haven't mentioned.When don't you need this?
For one table with a few columns that you could just as well keep in a spreadsheet, you don't need a design.
If you already have a schema and only need a query, write the question and the schema straight into the AI. The questions about system and size are then answered, because the schema answers them.