Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Unique Identifier Key of One Table to Foreign Key of Another 1

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
If I have a field in one table that is a uniqueidentifier, how do I set up the field in a second table to have a one-to-many relationship to that uniqueidentifier?

Also, I have a small number of records, is there a better way to handle unique identification that would be automatic? The uniqueindentifier is 16 bytes large from what I understand, and an auto-incremented short would do, I just don't know how to set that up with SQL Server.
 
You could set the identity field to type int, in design view select

identity yes
identity seed 1
identity increment 1

This will give you an automatically populating integer key field.

Then to set up the foreign key relationship make sure that the corresponding field in the second table is the same data type. In design view of your table click the relationships button which shoudl be third in from the right ... and you can create the foreign key in there.

Transcend
[gorgeous]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top