Querious

Indexes and Keys

Indexes and Keys

The “Indexes & Keys” view is where you can change indexes, foreign keys, and the primary key on your tables.

To create an index:

  1. Select the table you want to add the index to in the Databases list on the left side of the window.
  2. Click on the add button under the Indexes list.
  3. Enter the name of the index.
  4. Choose the index Kind and Type.
  5. Separate the columns included in the index by commas.

To change the primary key:

  1. Select the table you want to add the index to in the Databases list on the left side of the window.
  2. For each of the colums you want to be in the primary key, simply click on the checkbox next to the column in the list.
  3. To limit a column’s role in the primary key to just a specific length of the column, enter the length in the Length column next to the column.

Foreign Keys

Foreign keys are only supported on InnoDB tables in MySQL 5. Therefore, to create foreign keys on a table, first make sure the table type is set to InnoDB using the “Table Info” view.

To create a foreign key:

  1. Select the table you want to add the index to in the Databases list on the left side of the window.
  2. Click on the add button under the Foreign Keys list.
  3. You can optionally enter a name for the foreign key, or leave it blank and have MySQL give the key a name for you.
  4. Double-click on any of the Columns, Foreign Table, or Foreign Columns columns of the row and a contextual window will popup.
  5. In the columns editor window, select the Foreign Table that the key will reference.
  6. All of the columns shown in the list are the columns in the table the foreign key is being added to. To map a “local” column to a column in the foreign table, simply select the foreign column from the popup next to the local column.