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
 General SQL Server Forums
 New to SQL Server Programming
 Primary Key

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-03-24 : 13:03:53
Hello,

I am creating a table where two of the columns are:
Social Number ID and Passport ID.

Considering both are unique which should I use for Primary Key?
Or should I create a ID from both columns? And how?

Thanks,
Miguel

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-03-24 : 13:14:35
If the combination of SocialNumberID and PassportID is unique and enforces the entity integrity of the table , then use the combination , otherwise look for an alternative , such as a single column.


Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-24 : 14:32:39
use a table level constraint on combination
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-03-24 : 14:52:16
Is this some kind of table for employees?
Have you considered that people may not have a Passport ID, or may not have as Social Security Number?

You probably would be better with an identity or uniqueidentifier column as the primary key.





CODO ERGO SUM
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-24 : 15:06:56
The one thing you can absolutely rule out is a composite PK of those two columns. How would that make any sense? Why would you want to allow rows with the same SS# but different passport ID's and vice versa?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-03-24 : 15:22:27
My idea is to use ID column, INT or UniqueIdentifier, as I always use.

I was just wondering of the advantages and disadvantages or using these two fields as Primary Key.

Note that in this case all users will have both a Social Number ID and Passport ID. The composite will always be unique.

I think that the only advantage will be using less space but ...

So I think I will keep using the INT or unique identifier ID column ...

Thanks,
Miguel
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-03-24 : 15:35:19
quote:
Originally posted by shapper
...Note that in this case all users will have both a Social Number ID and Passport ID. The composite will always be unique...



Famous last words.



CODO ERGO SUM
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-24 : 16:14:46
Again:

Why would you want to allow rows with the same SS# but different passport ID's and vice versa?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -