Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Jaykappy
Starting Member
19 Posts |
Posted - 2011-12-09 : 10:35:40
|
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 valueI 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 relationshipOn new Parent Record a new GUID will be createdOn 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 - 2011-12-09 : 12:59:19
|
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 relationshipBUT 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 |
|
|
|
|
|