Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Primary Key Implementation Issue


Primary Key Implementation Issue

Author
Message
trapnell
trapnell
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 39
I need to create a Directory table for a project within an institute. How shall I implement a primary key, given the following?

a) The Directory must be referenced by many other tables in many other databases, some of which will not reside in the same instance of SQL Server.
b) The Institute provides InstitutePersonKey, which is guaranteed to represent a specific person, and only that person, forever. However,
c) Some people need to be added to one or more of the referencing databases, and therefore to the Directory, before they obtain an InstitutePersonKey.
d) Some, but not all, of these will eventually obtain an InstitutePersonKey.
e) Many of the referencing tables will have more than one column referening the primary key of the Directory.

Based on what I’ve read and tried,

a. I cannot use foreign keys to reference the Directory from other databases.
b. Even if a. is wrong, I cannot use cascading updates in those references.
c. Even if a. and b. are both wrong, I cannot have two columns in the same table each of which references the Directory with cascading updates, even if the table is in the same database as the Directory.

This suggests that creating a fake InstitutePersonKey of my own, to be replaced with a real one if/when the institute issues one, is likely to be cumbersome and subject to error.

One approach is
1. Make up my own primary key (for example [last name]+’|’+[first name]+seq where seq is an integer incremented to avoid duplicates).
2. Add a InstitutePersonKey column, which is constrained to be either
a. NULL, or
b. a unique valid reference to InstitutePersonKey in the Institute data warehouse.

Suggestions would be greatly appreciated.

Thanks,
Tom
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478
Use surrogate Primary Key (the best and simple in in SQL server will be having INT IDENTITY PK, you don't need to add "firstname+lastname" to it). Use IndividualPersonalKey as another key which can be unique but null-able. It's quite common problem met by database designers and using surrogate keys does help to solve this problem in simple and elegant way.
And...
Disregard J.C. comments if he will post here and suggest using fake ones with later update to the real ones - huge headache for no gains!
Can you be absolutely sure that whoever issue IndividualPersonalKey's will never decide to reuse ones?

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16632 Visits: 17024
Eugene Elutin (10/24/2012)
Use surrogate Primary Key (the best and simple in in SQL server will be having INT IDENTITY PK, you don't need to add "firstname+lastname" to it). Use IndividualPersonalKey as another key which can be unique but null-able. It's quite common problem met by database designers and using surrogate keys does help to solve this problem in simple and elegant way.
And...
Disregard J.C. comments if he will post here and suggest using fake ones with later update to the real ones - huge headache for no gains!
Can you be absolutely sure that whoever issue IndividualPersonalKey's will never decide to reuse ones?


+1 on the identity. This seems to be a perfect fit.

And as Eugene said, don't add the firstname+lastname to it. That will cause you nothing but grief. You will end up with a primary key containing a name that is no longer valid when somebody changes their name. This type of demographic data should not be considered part of a key because it can change.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search