SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Primary Keys - UNique Values - Foreign Keys
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jaykappy
Starting Member

19 Posts

Posted - 12/09/2011 :  10:35:40  Show Profile  Reply with Quote
I have a couple questions related to another post but diodnt want to string that post along.
I have 2 tables and trying to figure out how to best handle the PK and FK to maintain relationship while creating new records etc.

I have a Primary Key in both tables (ID), this field in both tables is an automnumber field that simply increase in number as more records are added.
I then created a ParentGUID field in the Parent table which will house a GUID value
I then created a ParentGUID field (varchar) in the Child Table as well as a ChildGUID which will house unique child guid for each record, where the ParentGUID in this child table will maintaint the relationship

On new Parent Record a new GUID will be created
On Child new record a ChildGUID will be created, and the ParentGUID will be grabbed from the Parent Table and placed in the table.

QUESTION:
If I make the ID fields in both tables the Primary Keys, how do I handle the ParentGUID in teh Parent Table, and the ChildGUID and ParentGUID in the Child table.

I assume that I cannot make 2 primary keys?
I need a foreign Key on the Child Table (ParentGUID field) back to the Parent Table (ParentGUID field)

Just a bit confused on the setup adn workign of the foreign keys....
I am seperating the ID from the GUIDs because in silverlight I am retrieving the parent GUID and manually placing it in the Childs ParentGUID field...If its the Primary key I dont see it in the silverlights datagrid, nor know how to retierve the PK...

Thoguths?

Jaykappy
Starting Member

19 Posts

Posted - 12/09/2011 :  12:59:19  Show Profile  Reply with Quote
I think my problem and why I have PK as the ID and then having the GUIDS is to first makle a unique value for each record and to maintan the relatiohsips of the Many to One.
In Silverlight I dont know how to retrieve the PK of a selected record as its not shown...but I can grab any other field value...the GUID being one of those...I create a new GUID on the Parent and Child on new record creation and set the ParentGUID on the child table (from the value of teh parent table) to create the relationship

BUT If I have ID fields in both tables as PK what do I do then? I need the "ParentGUID" field of the Child table to be Foreign Key back to the Parent Tables "ParentGUID" field.

I can make a FK on the child table...
Do I need to make another PK on the Parent Tables ParentGUID field?

Does a Foreign Key have to point back to a Primary Key?

THanks

Edited by - Jaykappy on 12/09/2011 13:14:55
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000