relationships in the logical database model


I'm using the program ERWin to design the logical database model. Has someone used it?

I'm having problems with the relationships.
If for instance I have these three tables:




The cod_table<n> are the Primary keys of the tables.
TABLE1 is related with TABLE2.
TABLE2 is related with TABLE3.

The problem is that cod_table1 goes to TABLE3 as Foreign Key when I set the relationships in this program, which I don't want it to happen.
cod_table1 (******)

How can I avoid that?

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

After selecting relationship type i.e. 1:n or 1:1, optional/mandatory, weak/strong entity, drag from center of TABLE1 to center of TABLE2 and relationship will be done with cod_table1 appearing in TABLE2 as FK.

Similarly, drag from center of TABLE2 to center of TABLE3 and relationship will be done with cod_table2 appearing in TABLE3 as FK. Now you are done.

Even if what you are saying is true, just delete the unwanted FK column(s) in child table(s).

lulonAuthor Commented:
I've tried to delete it but it does not allow to delete cod_table1 in TABLE3
You need to delete the relationship first, then delete cod_table1 in TABLE3. Relations also to be deleted in a particular order. Also, try deleting cod_table1 from other tables.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ioannis AnifantakisProgramming InstructorCommented:
Listen, your connection is the following

Table3 -> Table2 -> Table1

Thats what table points to what table.  You don't need to set pointer from table3 to table1, as its infact pointed by table2.  So if you point table3->table2, then since table2->table1, you also have the table3->table1 through the table2.

Correct me if I don't get something in your question, but you, yourself, mentioned that its incorrect to point from table3 to both table2 and table1.
lulonAuthor Commented:
Hi ioannisa,

You are right. The thing is that my database is already design and I have what I pasted in the beginning.
TABLE2(cod_table2, cod_table1)
TABLE3(cod_table3, cod_table2)

There is no need to have cod_table1 in TABLE3 since I can get it through cod_table2.

Now I am documenting the database design and I'm using ERWin, have you ever used it? When I set the relationships between the three of them (table1 -> table2; table2 -> table3), cod_table1 goes to TABLE3.
Ioannis AnifantakisProgramming InstructorCommented:
I haven't used the specific tool, but if ERWin does introduce that table1->table3 connection, it might be due to the following reason.

1) if you make a select statement to have no need to include table2 in your where statement (yes its faster but its wrong when it comes to ER Design theory).

However if its done, I bet that cod_table1 in table3 must have null default value.  When a key has null default value, it means that when its having its value null, then the database won't introduce some error to the corresponding foreign key value.  Database will complain only if i you try to pass a value that doesn't exist on the foreign table.

Therefore ERWin is probably trying to give you some "feature" here with only logical explanation the things I wrote in the above two paragraphs.

Other than that, there might be some setting as to not use "intuitive" relationships or something.
lulonAuthor Commented:
I know it should be like you say but it does not work. Sorry but I cannot accept it as a solution...
I think you may have got your relationships "wrong way round". You say "table1 -> table2" but judging by your column names Table1 looks like the PARENT (referenced) table of table2 and notationally that is usually written as "table2 -> table1". Similarly, you need to make sure that table2 is referened as the PARENT of table3. Maybe that is where your problem lies.
Correct, FK is derived from PK i.e. child is derived from parent. Hence, we should click in middle of parent table and drag relation to child table. Also, it depends tool to tool what happens if you pre-create FK column before setting the relation or otherwise.

Normally, you get a column in child table on making the relation with same name as that of PK as FK. Then you can rename the column to what you desire if you feel so.

It appears the other way round since crows feet/arrow mark is pointing to child table.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.