Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 PK is FK too?

Author  Topic 

lynda
Starting Member

21 Posts

Posted - 2009-06-29 : 14:04:07
In the database that I use, there are tables like:

User

ProductTypeUser

In USER there is a PK identity column called ID.
In ProductTypeUser the PK is also ID, not identity and is FK to the PK in USER.

What is the advantage of this? Is this a better design than having a typical ID int identity column as the PK and a seperate FK column that relates back to the PK in USER?

Thanks much!

Mike

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-06-29 : 14:26:55
That would indicate that it is a one-to-(zero or one) relationship. So you cant have more than one ProductType per userID. ProductTypeUser becomes kind of an extension to the [USER] table. The advantage could be to sort of partition the data between the two tables making two narrower tables rather than t wide table. A possible reason to seperate the tables is if you have many Users that don't have any productType info.

Be One with the Optimizer
TG
Go to Top of Page

lynda
Starting Member

21 Posts

Posted - 2009-06-29 : 14:52:07
Ahh excellent, that makes total sense since indeed, there will be a subset of records in ProductTypeUser of those records in USER (so indeed a one-to-(zero or one) exists).

Thanks!
Go to Top of Page
   

- Advertisement -