Short answer: turn the assignment into requirements, pick the entities, define the relationships and their cardinality, choose primary and foreign keys, normalize to third normal form, then draw the ER diagram and write the CREATE TABLE SQL. To check your work, describe the same system in AI2SQL's design mode and compare its tables and diagram with yours.
The six steps
- Write down the requirements. List what the system must store and the questions it must answer, in plain sentences taken from the assignment, for example: members borrow copies of books and pay a fine when a loan is late.
- Pick the entities. Underline the nouns that have their own data (member, book, copy, loan, fine). Each becomes a table; nouns that only describe something (title, due date) become columns.
- Define the relationships and cardinality. For each pair of entities decide one-to-one, one-to-many or many-to-many. Put the foreign key on the many side, and give every many-to-many relationship its own table.
- Choose primary and foreign keys. Give each table a primary key (a surrogate id or a natural key such as an ISBN), then add the foreign keys and decide what happens on delete.
- Normalize to third normal form. Remove repeating groups (1NF), make non-key columns depend on the whole key (2NF) and remove columns that depend on other non-key columns (3NF).
- Draw the ER diagram and write the SQL. Draw the ERD, write the CREATE TABLE statements, insert a few sample rows and run the queries the assignment asks for to prove the design works.
Six database project ideas, with their tables
| Project | Tables | The relationship to get right |
|---|---|---|
| Library management | members, books, authors, book_authors, copies, loans, fines | books ↔ authors many-to-many; a copy has many loans over time |
| Course registration | students, instructors, courses, sections, enrollments, prerequisites | students ↔ sections through enrollments; courses reference themselves for prerequisites |
| Hospital appointments | patients, doctors, departments, appointments, prescriptions, medications | doctors belong to a department; an appointment links one patient and one doctor |
| Online store | customers, addresses, products, categories, orders, order_items, payments | orders ↔ products through order_items, which stores quantity and price at the time of sale |
| Gym membership | members, plans, memberships, trainers, classes, class_bookings | a member has many memberships over time; members ↔ classes through class_bookings |
| Hotel reservations | guests, rooms, room_types, reservations, reservation_rooms, invoices | one reservation can cover several rooms; room availability comes from date ranges |
Worked example: a library system
Assignment: "Members borrow copies of books. A book can have several authors and several copies. A loan has a due date; a late return creates a fine."
Entities: members, books, authors, copies,
loans, fines. Books and authors are many-to-many, so they get a
book_authors table. A book has many copies, a copy has many loans over time, and a loan has
at most one fine. In PostgreSQL:
CREATE TABLE members (
member_id SERIAL PRIMARY KEY,
full_name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
joined_on DATE NOT NULL DEFAULT CURRENT_DATE
);
CREATE TABLE books (
isbn TEXT PRIMARY KEY,
title TEXT NOT NULL,
published INT
);
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY,
full_name TEXT NOT NULL
);
CREATE TABLE book_authors (
isbn TEXT REFERENCES books(isbn),
author_id INT REFERENCES authors(author_id),
PRIMARY KEY (isbn, author_id)
);
CREATE TABLE copies (
copy_id SERIAL PRIMARY KEY,
isbn TEXT NOT NULL REFERENCES books(isbn),
shelf TEXT
);
CREATE TABLE loans (
loan_id SERIAL PRIMARY KEY,
copy_id INT NOT NULL REFERENCES copies(copy_id),
member_id INT NOT NULL REFERENCES members(member_id),
loaned_on DATE NOT NULL,
due_on DATE NOT NULL,
returned_on DATE,
CHECK (due_on >= loaned_on)
);
CREATE TABLE fines (
loan_id INT PRIMARY KEY REFERENCES loans(loan_id),
amount NUMERIC(8,2) NOT NULL CHECK (amount > 0),
paid BOOLEAN NOT NULL DEFAULT false
); Two queries that prove the design answers the assignment's questions:
-- Overdue loans with the member's email
SELECT m.full_name, m.email, b.title, l.due_on
FROM loans l
JOIN members m ON m.member_id = l.member_id
JOIN copies c ON c.copy_id = l.copy_id
JOIN books b ON b.isbn = c.isbn
WHERE l.returned_on IS NULL AND l.due_on < CURRENT_DATE;
-- Unpaid fines per member
SELECT m.full_name, SUM(f.amount) AS owed
FROM fines f
JOIN loans l ON l.loan_id = f.loan_id
JOIN members m ON m.member_id = l.member_id
WHERE NOT f.paid
GROUP BY m.full_name
ORDER BY owed DESC;
Why it is in third normal form: author names live only in authors, the title lives only
in books (not repeated on every copy), and the fine is keyed by the loan it belongs to.
Mistakes that cost marks
- A many-to-many without its own table, such as an
author_idscolumn holding a comma-separated list. - Mixing up a thing and its copies or instances: a book versus a copy of it, a course versus a section of it.
- Storing values you can calculate, such as a member's age or an order total that is not a price snapshot.
- Missing foreign keys, so the ER diagram shows tables that are not connected.
- No sample data or test queries, so nothing shows the design actually answers the questions.
Using AI2SQL for your project
Open design mode and describe the system the way the assignment does. AI2SQL returns the tables, keys and CREATE TABLE SQL for PostgreSQL, MySQL, SQL Server or Oracle and draws the ER diagram. Compare it with your own design, ask why it chose a key or a table, and ask for changes ("add a reservation queue for books that are out"). You can also paste the CREATE TABLE statements you wrote to get your diagram drawn and run practice queries against it. Follow your course's rules on AI tools, and make sure you can explain every table yourself.
More on the tool itself: AI ERD generator. More on the theory: database normalization with examples.