Как я могу создать обязательные неидентифицирующие отношения между двумя объектами?

7441
Cam Jackson

Я работаю в MS Visio 2010. Это актуальная часть моего ERD:

ERD

Связь между Событием и Приключением правильная: существует внешний ключ от События к Приключению, и этот FK является частью первичного ключа События.

Тем не менее, я не могу понять, как сделать линию отношений между приключением и типом размещения такой же, как и между событием и приключением, не делая эти отношения частью ПК приключения. Когда я смотрю на «Разные» свойства этой линии отношений, я хочу, чтобы это было:

  • Кардинальность: ноль или более
  • Тип отношений: Неидентифицируемый
  • Ребенок имеет родителя: не обязательно (обязательно)

Но флажок для третьего свойства неактивен и переключается между Истиной / Ложью, когда я делаю связь Неидентифицирующая / Идентифицирующая.

Единственный способ выяснить это - отсоединить два столбца от вкладки «Определение», которая затем снимает флажок «Необязательно», но затем я теряю свойство внешнего ключа в столбцеtainType, и в то время как символы отношений правильно, линия остается пунктирной.

Как сделать так, чтобы количество элементов в строке слева отображалось так же, как и в строке отношения справа, без добавления аккомпанемента к PK Adventure?

3

2 ответа на вопрос

1
Air

This MS TechNet thread identifies the problem as having to do with the way that Visio 2010 automatically inserts the foreign key when you create a relationship between entities:

It indeed seems that typing the foreign key field name first and then establishing the relationship makes this possible. Checking/unchecking Req'd on the foreign key then automatically checks/unchecks Optional on the relationship.

There are two ways to solve this problem, depending on whether you are creating a new relationship on your diagram or trying to fix an existing one.

How to create a mandatory, non-identifying relationship

Before creating the relationship, add the desired FK attribute(s) to the child entity, using the same name(s) as in the PK of the parent entity. Make sure the "Req'd" option is checked for each FK attribute.

In your example, we add a "name" attribute to the Adventure entity:

Now adding the relationship automatically creates the FK but preserves the non-identifying, non-optional state of the existing attribute on Adventure:

You are free to rename the FK attribute however you like at this point.

Note that the "Child has parent: Optional" check-box is still grayed out. Even after this point, changing the properties of the relationship and/or the attributes involved sometimes have undesired side effects, and you may find the wrong crow's foot symbol getting "stuck" again. Fortunately, there's a quicker way to fix this than deleting the relationship and starting over.

How to fix an existing relationship

Select the relationship with the "stuck" crow's foot symbol and go to the Definition tab in the Database Properties window.

You will see a line with arrows connecting the PK and FK attributes in the parent and child entities. Select the connected attributes in both tables and disconnect them by clicking the button in the middle column. If the key is compound, you'll see multiple pairs of attributes:

Once you've disconnected all the attributes involved in the relationship, the "Child has parent: Optional" box in the Miscellaneous tab will become active again. Set the properties of the relationship to be Non-identifying with Optional parent, double check that the FK attributes in the child entity are set to "Req'd" and then go back to the Definition tab and re-associate the PK and FK attributes:

-1
rogal111

Visio автоматически добавляет столбец внешнего ключа при создании новых отношений. Чтобы изменить обязательные отношения, просто установите обязательный атрибут этого столбца (в свойствах объекта, вкладки столбцы).

Похожие вопросы