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:
-
Select the table you want to add the index to in the Databases list on the left side of the window.
-
Click on the add button under the Indexes list.
-
Enter the name of the index.
-
Choose the index Kind and Type.
-
Separate the columns included in the index by commas.
To change the primary key:
-
Select the table you want to add the index to in the Databases list on the left side of the window.
-
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.
-
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:
-
Select the table you want to add the index to in the Databases list on the left side of the window.
-
Click on the add button under the Foreign Keys list.
-
You can optionally enter a name for the foreign key, or leave it blank and have MySQL give the key a name for you.
-
Double-click on any of the Columns, Foreign Table, or Foreign Columns columns of the row and a contextual window will popup.
-
In the columns editor window, select the Foreign Table that the key will reference.
-
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.