By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,266 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,266 IT Pros & Developers. It's quick & easy.

Foreign Key Type for "uniqueidentifier"

NeoPa
Expert Mod 15k+
P: 31,533
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 "uniqueidentifier" GUID field that would be helpful.
Nov 27 '08 #1
Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,533
I did some further searching and I think the answer is that the type is actually the same ("uniqueidentifier"), 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)
Expand|Select|Wrap|Line Numbers
  1. Field       Type          IndexInfo
  2. HdrID       uniqueidentifier  PK
  3. Various Header related fields...
Table Name=[tblTHDSOP] (AKA Detail)
Expand|Select|Wrap|Line Numbers
  1. Field       Type          IndexInfo
  2. DtlID       uniqueidentifier  PK
  3. HdrID       uniqueidentifier  FK
  4. Various Detail related fields...
Nov 27 '08 #2

debasisdas
Expert 5K+
P: 8,127
That depends how frequently you use the field in SQL directly. Indexes has negative effect during hugh data loading.
Nov 29 '08 #3

NeoPa
Expert Mod 15k+
P: 31,533
@debasisdas
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?
Nov 30 '08 #4

debasisdas
Expert 5K+
P: 8,127
Yes the indexes need to be created separately. Specifying the relationship based on PK & FK will not do that automatically for you.
Dec 1 '08 #5

NeoPa
Expert Mod 15k+
P: 31,533
Thanks for that Debasis.

All sorted cheers :)
Dec 1 '08 #6

amitpatel66
Expert 100+
P: 2,367
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!!
Dec 5 '08 #7

NeoPa
Expert Mod 15k+
P: 31,533
@amitpatel66
Yes. Thanks Amit :)
Dec 5 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.