ER Diagram - how to relate/join these tabels?

See Attachment:

As you can see I have a "ContactInformation" table
I then have two country fields
- Country (which is the country of the account holder)
- CountryOfCitzenship (as the name suggest this is the country of citizenship)

How do I join the yellow table with the orange table?
countryerd.jpg
KhouAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
Yes, one "physical" Country table only, but two instances.

Even Microsoft Access can do this (not for modelling though, but for defining relations), so Erwin must have this ability too, for example for creating a self-join.

/gustav
0
 
Gustav BrockCIOCommented:
You create a second instance of Country, aliased say Country_1 or CountryCitizenship, and relate that to CountryOfCitizenship.

/gustav
0
 
Arthur_WoodConnect With a Mentor Commented:
With Two instances of the Country table, you join the First instance to your Contact information table, on the Country field, and the second instance (CountryCitizenship) on the CountryOfCitizenship field.

You cannot have a single instance of Country, joined to both fields.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
johnsmith1962Commented:
I am pretty sure you can do that with ERwin.  That is use one table for both foreign keys.  This is really a question of  how your ER diagramming software works, not Oracle.  But if your software wont let you use one table for both fields, than the answer above will work.
0
 
KhouAuthor Commented:
Are both diagrams correct?
See Diagram ER A or ER B


countryerdlinked.jpg
countryerdlinked2.jpg
0
 
KhouAuthor Commented:
ER A:
Contactinformation table has two foreign keys
1 x FK CountryID (has 1 to 1 with Country table)
1 x FK CountryCitizenshipID (has 1 to 1 with Country table)


ER B:
Contactinformation table has two foreign keys
1 x FK CountryID (has 1 to 1 with Country table)
1 x FK CountryCitizenshipID (has 1 to 1 with CountryCitizenship table)

CountryCitizenship table has 1 foreign key
1 x FK CountryID (has 1 to 1 with Country table)
0
 
Gustav BrockConnect With a Mentor CIOCommented:
Well, to be precise, you use one table but two instances of this.

I'm pretty sure Khou knows how to deal with the first instance for the country and explained how to add the second instance for the citizenship. Arthur describes the full process.

If an ER programming tool did not behave this way visually, it had to do so behind the scene.

/gustav
0
 
Gustav BrockCIOCommented:
Neither is right.

Contactinformation table has two foreign keys
1 x FK CountryID (has 1 to 1 with Country table)
1 x FK CountryCitizenshipID (has 1 to 1 with Country table As CountryCitizenship)

CountryCitizenship (or any other name different from Country) is an alias for table Country.

/gustav
0
 
KhouAuthor Commented:
Hi Cactus

Cant figure out how to create Alias! (Using Visual Paradigm)
can you show me how it looks like with VP? or any other ER software.
0
 
KhouAuthor Commented:
why is diagram ER A and ER B wrong?
0
 
KhouAuthor Commented:
Hi Experts!

This is not going to work? (see diagram ER A, ER B)



Diagram ER A:ContactInformation Table
FK CountryID = 1111 <-- is FK of countryID
FK CountryOfCitizenshipID = 1111 <--- is FK of CountryID
Country Table
PK CountryID = 1111, name = Australia
PK CountryID = 7777, name = United Kingdom



Hence, ContactInformation table
Country = Australia
CountryOfCitizenship = Australia


-----------------------------------------------------------------------------------------------------
Diagram ER B:ContactInformation Table
FK CountryID = 1111 <-- is FK of countryID
FK CountryOfCitizenshipID = 12345 <--- is FK of CountryOfCitizenship

Country Table
PK CountryID = 1111, name = Australia
PK CountryID = 7777, name = United Kingdom

CountryOfCitizenship Table
PK CountryOfCitizenshipID = 12345, FK CountryID = 1111



Hence, ContactInformation table
Country = Australia
CountryOfCitizenship = Australia
0
 
Gustav BrockCIOCommented:
ER A will not do because you cannot have a single instance of Country joined to two fields in the same table (except if these for each record carried the same value which wouldn't make sense).

ER B assumes that some relation exists between country of address and country of citizenship which, I guess, is not the case neither here nor in general.

In most ER designers with a GUI you can drag and drop a table on the pane to create an instance of that table. This instance is typically given the name of the table, here Country. If you do it twice, the second instance is typically aliased with a trailing "_1", here Country_1. This alias (a property of the instance) you can typically later rename to what you prefer other than any other table name/alias already existing on the pane.

So, you should end up with something like this:

ContactInformation Table
FK CountryID = 1111 <-- is FK of countryID
FK CountryOfCitizenshipID = 77777 <--- is FK of CountryOfCitizenship

Country Table
PK CountryID = 1111, name = Australia
CountryOfCitizenship alias  <--- Country_1, alias for Country Table
PK CountryID = 7777, name = United Kingdom

/gustav
0
 
KhouAuthor Commented:
Understood, but unable to draw this with the tool,
ie "In most ER designers with a GUI you can drag and drop a table on the pane to create an instance of that table."

Such as ERWIN?

-how would you do this in SQL Management Studio? or
-Visual Paradigm?

By the way "CountryOfCitizenship alias  <--- Country_1, alias for Country Table" this is not a physical table is it!. im unable to create this.
0
 
KhouAuthor Commented:
by the way, was this a mistake? You have two Primary key for CountryID.


Country Table
PK CountryID = 1111, name = Australia
CountryOfCitizenship alias  <--- Country_1, alias for Country Table
PK CountryID = 7777, name = United Kingdom
0
 
Gustav BrockCIOCommented:
In Visual Studio you can do it in the DataSet designer, but that probably won't help you.

According to this, SQL Server Management Studio 2005 has a limitation:

http://www.windows-tech.info/15/a47ed0ff53dbd825.php

I don't know about Erwin - too pricey for me - but I'm confident it has this capability.

/gustav


0
 
KhouAuthor Commented:
Hi, to clarify

May I know when you create the "Country" and "Country_1" table, are they actually meaning the same underlying table, or 2 separated table actually?
0
 
KhouAuthor Commented:
I can create a self join in my software, but i thought you wanted to create a table alias?
am I understanding this wrong?

Could you draw up a simple diagram with this an alias? so I can see how it actually looks like!
0
 
Gustav BrockCIOCommented:
Yes.
It is not a self-join, only that the visualization is much like this.

/gustav
countryerdlinked-1.jpg
0
 
KhouAuthor Commented:
cactus_data: why wouldnt this work? (see diagram).

erd.jpg
0
 
Gustav BrockCIOCommented:
I guess it would, but you would introduce a relationship between country of address and country of citizenship which I don't think exists. And if not, this setup will over-complicate things.
It may, however, be correct for your scenario. If you are unsure about this, your client must provide more information.

/gustav
0
 
Mariner73Connect With a Mentor Commented:
Only a suggestion:
Can you put 2 FK into ContactInformation Table,
that points to Country tabe?
like in some previous coment:
Diagram ER A:
ContactInformation Table
FK1 CountryID = ---> is FK to countryID
FK2 CountryOfCitizenshipID = ---> is FK to CountryID

Or you can create in Erwin "Logical link" without any FK at least if you don't need them explicitly.
0
 
KhouAuthor Commented:
Thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.