What it's for
A database stores the information a website collects or works with: customers, bookings, orders, posts. The Database Builder helps in two situations:
- Starting a new one: describe the tables in plain words, and it writes the SQL for MySQL / MariaDB (what cPanel and phpMyAdmin use) or SQLite (a database in a single file, handy for small apps).
- Checking one that exists: open its structure to see how the tables fit together, and let the health check find common problems, each with the SQL to fix it.
It never connects to your server. You import or run the SQL yourself, so nothing changes until you decide.
Quick start
- Start from a design: click Start from… and choose one, such as Customers and invoices, or click + Table to begin from scratch.
- Choose the database type at the top: MySQL / MariaDB or SQLite.
- Click a table in the diagram to change its name and columns on the Table tab.
- Check the Health check tab for anything to fix.
- Get the SQL from the SQL tab, or Download › SQL to create it.
Your design is kept in this browser. To keep a copy or move it to another computer, use Download › Design file, and Open… it later.
Tables and columns
A table holds one kind of thing, such as customers. Each column is one piece of information about it, such as a name or an email address. Each row is one customer.
Every new table starts with an id column, numbered automatically (1, 2, 3…). That's the table's primary key: the number that identifies each row. Keep it.
For each column, give a name and choose a type in plain words: Short text, Long text, Email address, Phone number, Whole number, Money, Yes / no, Date, Date and time, Choice from a list, or Link to another table. The tool picks the right SQL type for each database. Tick Required if a row can't be saved without it.
Click the arrow at the end of a column for more:
- Longest (short text), digits (money), or the list of choices.
- Default: the value a new row gets when none is given. For dates and times, The time it's saved fills in the moment the row is created.
- No two rows the same: for things like email addresses or invoice numbers.
- Fast to search: adds an index, for columns you often look things up by.
- Up, Down and Remove column.
The dashed buttons under the columns add common ones in a click, such as email or created_at. Names work best in lower case with underscores, such as first_name; the tool tidies them as you type.
Ctrl+Z or the arrow button undoes the last change.
Links between tables
Links are what make a database more than a spreadsheet. An invoice belongs to a customer, so the invoices table has a customer_id column that holds the customer's id.
Links are made automatically: name a column after another table with _id at the end, such as customer_id when there's a customers table, and it's linked as soon as you stop typing. The diagram draws the line: the forked end is at the "many" side (one customer, many invoices). You can also click + link to … under the columns, or choose Link to another table as the type and pick the table.
For each link, choose what happens when the row it points to is deleted:
- Don't allow it while linked: a customer with invoices can't be deleted. The safe choice, and the default.
- Delete these rows too: deleting an invoice deletes its lines. Use it for things that can't exist on their own.
- Clear the link: the row stays, but no longer points anywhere. The column must then be allowed to be empty.
Posts can have many tags, and tags many posts. That needs a small table in between with two links, such as post_tags with post_id and tag_id, both ticked as Primary key. The Blog design shows how.
Getting the SQL
The SQL tab shows the SQL that creates the whole database, updated with every change. Tables come in the right order, so each one exists before another links to it.
- Skip tables that already exist (on) makes it safe to run twice.
- Replace existing tables deletes them first, with their data. Only use it on an empty or test database.
MySQL / MariaDB in cPanel
- Create the database and a user with MySQL Database Wizard in cPanel.
- Open phpMyAdmin, click the database on the left, then Import.
- Choose the file from Download › SQL to create it, and click Import. Or paste the SQL into the SQL tab and click Go.
SQLite
Run the SQL once from PHP to create the database file, keep the file outside the website folder, and turn links on each time you connect. The How to use it section of the SQL tab shows the three lines of PHP.
Checking an existing database
First get its structure:
- MySQL / MariaDB: in phpMyAdmin, click the database, then Export › Custom, choose Structure only (data isn't needed), and click Export.
- SQLite: in DB Browser for SQLite, File › Export › Database to SQL file, with Export schema only.
Then click Open… and choose the file, or Paste SQL…. If the file also contains data, only the structure is used.
The Health check tab lists what it finds, most serious first:
- No primary key: rows can't be edited or linked reliably.
- Old storage engine (MyISAM): can't enforce links, and is easily damaged.
- Old character set (
utf8,latin1): emoji and some accents turn into question marks. - Looks like a link, but isn't one: nothing stops a row pointing at something that doesn't exist.
- Linked columns of different types: MySQL refuses the link.
- Money stored as a decimal number: totals can be off by a cent.
- Extra or doubled indexes, dates stored as text, and names that are SQL words.
Click a problem's button to fix it. The design changes, and the change is added to SQL for your existing database at the bottom, in a safe order. Run that in phpMyAdmin's SQL tab, or download it with Download › SQL with the fixes. For SQLite, which can't change most of a table in place, it rebuilds each table and copies the data across.
Always export a full backup (structure and data) before running fixes on a real database. If adding a link fails, some rows point to records that no longer exist; the comment above that line gives the query that finds them.
Changes you make by hand in the design aren't added to the fix SQL, only the health check's fixes are.
Questions
Can it connect to my database?
No. It works only with SQL text, which keeps your database safe: nothing changes until you run the SQL yourself.
Can I open a WordPress database?
Yes, its structure. WordPress doesn't use database links, so the health check suggests many; WordPress manages those itself, so don't add them to a WordPress site.
Does it add data, or forms to enter it?
Not yet. It designs the structure. Entering data is done in phpMyAdmin, or by the website's own code.
Is my design sent anywhere?
No. Everything stays in this browser.