Solved

sql server Foreign Key to a GUID

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error when loading the database 16 54
Optimizing a query 3 33
SQL Server Deadlocks 12 47
Help Extract Specific in SQL 8 16
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now