Primary Key Implementation Issue

  • 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

  • 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[/url]

  • 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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply