Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL PrimaryKey best practice

Posted on 2011-03-16
Medium Priority
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?
Question by:AkAlan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
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.

Author Comment

ID: 35149770
Ok, I thought that was so, I was just thinking about any performance issues that could cause. Thanks.
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
LVL 10

Accepted Solution

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.

Author Closing Comment

ID: 35162240
Thanks to both.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach 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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…

688 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