Help Tables, columns and indexes

Creating an index

Indexes are made on the 2 Indexes tab of the table designer. You can add them while creating a table or later to an existing one; either way nothing reaches the server until you click Save.

The table designer, Indexes tab

Opening the Indexes tab

The grid

Each row is one index. Existing indexes are listed first; type in the empty row at the bottom to add one.

Grid columnWhat to enter
Index NameThe index’s name. Leave it empty and bonSQL writes no name, so the server chooses one. A primary key is always called PRIMARY and cannot be renamed.
ColumnsThe columns in the index. Click the cell’s button to choose them; see below.
Index TypeKEY (an ordinary index), UNIQUE, PRIMARY or FULLTEXT. Left empty, bonSQL writes a plain index.
VisibilityVisible or Invisible, written after the column list. Shown on MySQL 8.0.11 and later only, not on MariaDB, and not available for the primary key.
CommentA comment stored with the index. Shown on MySQL 5.5.3 and MariaDB 5.5 and later.

A table has at most one primary key: choosing PRIMARY on a second row gives Multiple primary keys cannot be defined.

Ticking PK? on the Columns tab adds the column to the PRIMARY row here, and creates that row if there is none, so you rarely need to make a primary key on this tab by hand.

Choosing the columns

The … button in the Columns cell opens the Columns window, which lists the table’s columns, including ones you have just added on the Columns tab and not saved yet.

  1. Tick the columns the index should cover.

  2. Use Up and Down to put them in the order the index should have.

  3. Optionally fill in:

    ColumnWhat it does
    LengthA prefix length, written after the column name as (20). Leave it empty for none.
    OrderASC or DESC. Shown on MySQL 8.0.11 and later only, not on MariaDB.
  4. Click OK. The cell then shows the columns as they will be written, for example `last_name`(20), `first_name`.

Adding, removing and saving

The green + button above the grid adds a row (Alt+Ins). The red - button deletes the rows whose box, at the start of the row, is ticked (Alt+Del); if no box is ticked, it deletes the row the cursor is in. bonSQL asks before dropping an existing index.

Click Save. For a new table the indexes become part of CREATE TABLE; for an existing table bonSQL sends add primary key (...), add unique index ..., add fulltext index ..., add key ... or add index ... inside its ALTER TABLE. An index row with no columns stops the save with No columns selected.

Tips