Solved

sql server Foreign Key to a GUID

Posted on 2014-09-12
3
239 Views
Last Modified: 2014-09-12
I have two tables, tblpeople and tbladdresses.  Both have a PersonID, in tblpeople that id is a Primary Key data type GUID.  In the tbladdresses it is a varchar, but has the same info from tblpeople but there are duplicates due to multiple addresses.  I am trying to get a foreign key reference but it is complaining about the data type issue.  What is the best way to fix this?
0
Comment
Question by:gwarcher
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 500 total points
ID: 40320224
I would recommend changing the datatype of the tblAddresses column to UNIQUEIDENTIFIER.  The datatype name "uniqueidentifier" does not mean that the value must be unique within the table.
0
 

Author Comment

by:gwarcher
ID: 40320237
I was not aware of that.  Thank you.  I thought it had to be unique.
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 40320262
It just means that it s intended to be globally unique so that if you execute NEWID() on multiple machines at the same time and/or the same machine multiple times you are "guaranteed" to get unique values in each case.  Actually this isn't 100% true but it is generally "true enough".
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question