Solved

sql server Foreign Key to a GUID

Posted on 2014-09-12
3
238 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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

770 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