Solved

SQL PrimaryKey best practice

Posted on 2011-03-16
5
250 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 333 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 333 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 167 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now