Redaa
Redaa

Reputation: 1590

How to create a zero or one to many relationship in Mysql workbench

In a database that have Orders, Customers tables, i need the relation between these two tables to be zero or one to many relationship, simply because in my application, an order can exist without being assigned to a customer.

One first idea that comes to my mind is to make the foreign key nullable, this way when creating an order the foreign key can be null, but i don't know how to do so. I'm working on a model so i can render it to my 'teacher', so i need to know how to do it using the EER diagram.

thanks in advance.

Upvotes: 8

Views: 35076

Answers (3)

Henry Obiaraije
Henry Obiaraije

Reputation: 448

Simply do it this way

  • Right click on the relationship and click on "Edit Relationship"
  • Switch to the "Foreign Key" tab by click on the tabs below the interface
  • Under Reference table section, uncheck the checkbox labeled "Mandatory"

There you go.enter image description here

Upvotes: 7

gomi
gomi

Reputation: 161

Mandatory option in "Foreign Key" tab in "Relationship" tab appears to be the way to control optionality.

Upvotes: 16

K.A.F.
K.A.F.

Reputation: 2337

Create your 1:n relationship as normal. Then double click the table to bring up the details. On your new FK field, uncheck the "NN" column. Now your FK can be NULL.

Upvotes: 7

Related Questions