December 17, 2003 at 1:52 am
Hi all
Could someone please comment on the design strategy of making use of related tables primary keys that become foreign keys in their child tables and also form part of the child table primary key. Please specify the pro's and con's of implementing this strategy.
Many thanks
Denzil Fillis
December 17, 2003 at 3:46 am
Sounds to me like a logical solution for typical one-to-many relationships.
From a technical point of view, you might consider placing a UNIQUE constraint on the child table (instead of the primary key) and using an identity value as primary key. This might improve performance if you have a multi-column primary key with large fields (eg. chars).
December 17, 2003 at 3:51 am
It might be that I don't understand your question correctly, but you're talking about one of the fundamental principles of relational databases.
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 17, 2003 at 4:33 am
quote:
Sounds to me like a logical solution for typical one-to-many relationships.From a technical point of view, you might consider placing a UNIQUE constraint on the child table (instead of the primary key) and using an identity value as primary key. This might improve performance if you have a multi-column primary key with large fields (eg. chars).
Thanks for the reply. This what I thought, the use of foreign keys as part of the primary key in child table could lead to performance problems.
December 17, 2003 at 4:43 am
quote:
It might be that I don't understand your question correctly, but you're talking about one of the fundamental principles of relational databases.Frank
I think u are misunderstanding my question. Is it a good idea to use foreign keys as part of a primary key in a child table eg
Claim table has a composite primary key say ClaimId and Version. Then we have a child table say Doctor with foreign keys from Claim table, ClaimId and Version which together with DoctorId form the composite primary key of the Doctor table. Is this prescribed or is it better to use DoctorId which is unique identifier as the primary key.
Regards
Denzil Fillis
December 17, 2003 at 5:08 am
Yes, you're right.
If I were aware that Noel already answered I wouldn't have posted at all.
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 17, 2003 at 6:50 am
Referntial Ontegrity Constraint Applied through Forigen Keys Keep You safe When you are trying to delete rows
But It can be very dangerous when you anble cascading delete.
Prefomarnce degregation are Imminent
Try implement referntial integrity in the applications and stored procedures.
December 17, 2003 at 7:12 am
You should clearly make the distinction between a primary key and foreign key. They are in no way related and serve completely different goals ...
A primary key is a way to uniquely identify a record in your table. This can be a composite key, but it does not have to be.
A foreign key is a way to enforce data integrity across tables.
If you have a one-to-many relationship, it is common practice to use the data of the primary key in the parent table as the reference in the child table. After all, the primary key uniquely identifies the record in the parent table.
But you can use just as well any other field (or combination of fields), as long as you are sure it uniquely identifies the record.
In a many-to-many relationship (brrr, the horror of it), you would never use a primary key of the 'source' table as a foreign key of the 'destination' table...
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply