Solved

sql server Foreign Key to a GUID

Posted on 2014-09-12
3
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

707 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