Search code examples
mysqlsqlmysql-workbenchworkbench

How to create composed key in Workbench?


I have table OrdersPhoto with two foreign keys: Order_Id and Photo_Id:

How to create a composed key based on them as: Order_Id__Photo_Id using Workbench? Should it be additional field, or just set up primary key for each?

enter image description here


Solution

  • For the PK you can create the composite key by simply activating the checkboxes for all columns participating in that key. For all others (and alternatively also for the PK) use the index tab in the table editor.

    enter image description here]

    Use the index details list to add and remove columns for a key. You can indicate the column order here too. Just change the number in the # column.