Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL PrimaryKey best practice

Posted on 2011-03-16
5
Medium Priority
?
276 Views
Last Modified: 2012-05-11
I am creating a table ProjectSites that will be a child table to another table Projects and it will only have three columns, here is the current schema

ProjectSites Table:

ProjectSiteID          identity  pk
ProjectID                int          fk
SiteID                     int          fk

So the idea is, there can be one or more Sites assigned to every project. There will never be a case where the same Site is assigned more than once to the same Project. My question is this, Should I make the PK of the table a combination of all three columns so that no mistakes can ever be made?
0
Comment
Question by:AkAlan
  • 2
  • 2
5 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 1332 total points
ID: 35149761
Yes that's the only way to meet all your conditions.
0
 
LVL 6

Author Comment

by:AkAlan
ID: 35149770
Ok, I thought that was so, I was just thinking about any performance issues that could cause. Thanks.
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 1332 total points
ID: 35149796
Will it impact performance? yes but  marginally given they are int columns. It is unavoidable given the requirements specified and best practice
0
 
LVL 10

Accepted Solution

by:
Asim Nazir earned 668 total points
ID: 35149831
You can also Add Unique constraint to two of the fields i.e. other than one PK field.
0
 
LVL 6

Author Closing Comment

by:AkAlan
ID: 35162240
Thanks to both.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question