Sean L. YoungStudio tools
Step 2 · Build

Database Builder

Design a database by naming tables and columns in plain words. Links between tables are made as you go, and the SQL is written for you. Or open an existing database's structure, see it as a diagram, find problems, and get the SQL to fix them.

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

  1. Start from a design: click Start from… and choose one, such as Customers and invoices, or click + Table to begin from scratch.
  2. Choose the database type at the top: MySQL / MariaDB or SQLite.
  3. Click a table in the diagram to change its name and columns on the Table tab.
  4. Check the Health check tab for anything to fix.
  5. 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.

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

  1. Create the database and a user with MySQL Database Wizard in cPanel.
  2. Open phpMyAdmin, click the database on the left, then Import.
  3. 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.

Back up first

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.