If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Erwin Fk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-23-09, 13:23
Love2Win Love2Win is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Erwin Fk

Hello all,

I have such question.
When I create relations in ERWIN it sets foreign keys (FK), Witch are primary keys from the related table. I understand this. But, it also sets FK from primary keys of the table is related to table related to this table.

for example:

table 1 -> table 2
pk - tbl1_id
===========
table 2 -> table 3
pk - tbl2_id
fk - tbl1_id
===========
table 3
pk - tbl3_id
fk - tbl2_id
fk - tbl1_id

ERWIN does it automatically when I set identifying relationships.
Why doest it do so? And what is sense of setting this cross table FKs
Is it good for db??
If it is bad how to disable it in ERWIN. To set foreign keys only to directly related tables. Or it is better to set fk for all tables that have relation to current table?
Reply With Quote
  #2 (permalink)  
Old 02-23-09, 14:12
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Could it be that you've unintentionally made a compound key out of the two columns in Table 2? That would explain why the two columns are then used for the foreign key in Table 3.

It might be clearer if you post the actual SQL for these tables rather than pseudo-code.
Reply With Quote
  #3 (permalink)  
Old 02-23-09, 14:13
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
ErWin is doing the right thing.

If the relationship between table1 and table2 is identifying, then a row in table2 can't exist without a corresponding row in table1 This in turn implies that the PK from table1 is actually a part of the PK of table2.

Since the PK of table2 is actually the combination of tbl1_id and tbl2_id, those two columns need to be carried forward into table3 as FK attributes.

ErWin is software, and like any software it could have bugs. You are wise to challenge what ErWin does automatically, but ErWin is one of the very few software packages that I will assume it is correct until I can positively prove that it is in error and that happens very, very rarely!

-PatP
Reply With Quote
  #4 (permalink)  
Old 02-23-09, 14:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by dportas
Could it be that you've unintentionally made a compound key out of the two columns in Table 2?
erwin makes a distinction between identifying realtionships and non-identifying relationships (there are two different buttons on the toolbar)

identifying relationships by definition propagate the keys

so it couldn't have been unintentional -- perhaps just unknowing

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-23-09, 15:22
Love2Win Love2Win is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Thnks Pat Phelan and all who answered. Now I get it!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On