Foreign Key Type for "uniqueidentifier"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    Foreign Key Type for "uniqueidentifier"

    SQL Server 2000.

    It's all in the title really. I have checked in quickbooks and done a quick search but time is critical just now.

    I will continue to explore other avenues, but if anyone knows how an FK field should be defined so that it can link into a "uniqueidentifi er" GUID field that would be helpful.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    #2
    I did some further searching and I think the answer is that the type is actually the same ("uniqueidentif ier"), but the default value and general setup are just done differently (Table ROWGUID not set for instance).

    Assuming that to be the case, here's another question :
    If I have two tables linked on a field (in this case HdrID - the unique ID of the header record) is it necessary for me to create an index of this field in the Detail record if I already have a Relationship Constraint set up?
    Table Name=[tblTHSOPH] (AKA Header)
    Code:
    [I]Field       Type          IndexInfo[/I]
    HdrID       uniqueidentifier  PK
    Various Header related fields...
    Table Name=[tblTHDSOP] (AKA Detail)
    Code:
    [I]Field       Type          IndexInfo[/I]
    DtlID       uniqueidentifier  PK
    HdrID       uniqueidentifier  FK
    Various Detail related fields...

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      That depends how frequently you use the field in SQL directly. Indexes has negative effect during hugh data loading.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        Originally posted by debasisdas
        That depends how frequently you use the field in SQL directly. Indexes has negative effect during hugh data loading.
        Thanks Debasis.

        I suppose I should have been clearer (although your answer implies yes I do). Does the index need to be specified separately, if you require it to be indexed? Put another way, does the relationship automatically create an index?

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Yes the indexes need to be created separately. Specifying the relationship based on PK & FK will not do that automatically for you.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            Thanks for that Debasis.

            All sorted cheers :)

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Yes the Index needs to be created seperately on the foreign key column ie on the HdrID of Details table.

              But Yes an Index gets created automatically when you define a PRIMARY KEY or UNIQUE KEY on any column of a particular table.

              Index does not get created automatically for any relationship defined.

              Hope this helps!!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32636

                #8
                Originally posted by amitpatel66
                Hope this helps!!
                Yes. Thanks Amit :)

                Comment

                Working...