Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Primary Key Implementation Issue Expand / Collapse
Author
Message
Posted Tuesday, October 23, 2012 2:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 05, 2014 10:15 AM
Points: 6, Visits: 22
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

Post #1376236
Posted Wednesday, October 24, 2012 1:56 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 03, 2014 10:10 AM
Points: 2,792, Visits: 4,874
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1376345
Posted Wednesday, October 24, 2012 8:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:28 PM
Points: 12,034, Visits: 11,062
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)
Post #1376500
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse