Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2012, 10:05 AM
Registered User
 
Join Date: Sep 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Candidate key vs Primary Key

New to Webmatrix, still reading. I have a many-to-many relationship between to tables. The reading (everywhere) is to put in a linked table between the two to simplify the linkage.

The question. Should the linked table have a PK field and two FK fields that point to their respective one-to-many tables or should the linked table have one field that is the concatination of the two PK from the primary tables.

Table 1 Table 2
table1Id (PK) Auto Increment Table2Id (PK) Auto Increment

LinkedTable
LinkedTableId (PK) Auto Increment
FK of table 1
FK of table 2

or

LinkedTable
FK1 + FK2 (PK)

Thanks
Dallas in Maryland
 
Old September 12th, 2012, 02:47 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You typically create a table that contains two columns, one for each foreign key. That way you can easily join them on the tables they are referring to.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
DMT20601 (September 17th, 2012)
 
Old December 22nd, 2012, 10:05 PM
Registered User
 
Join Date: Sep 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default multi column primary key

I had ask this question back in Sept 2012. I got a response that was surely the right direction. Today, I can be more accurate about what I need to do within Webmatrix.

I have a linked table for a many-to-many relationship. The table only has two columns PKtable1id and PKtable2id.

For it to be within the structure of Webmatrix it needs a multi column primary Key to insure uniqueness.

It easy to build this little table with the IDE but how do you configure the primary key?

Is the IDE going to let me check primary key on both columns?

or can I build a query script (Create Table) and apply a constraint for the multi column pk.


Thanks

Dallas in Maryland.
 
Old December 23rd, 2012, 04:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

When you create the junction table, set the Is Primary Key property of both columns to True. This way, you create a composite key which in turn means each combination can only exist once.

Next, for this table, click New and create a new Relationship between the Foreign Key Table (the junction table) and the first Primary Key table. In your case, link PKtable1id to the ID of Table1. Then repeat this for the second table and link PKtable2id to the primary key of Table2.

This way, the individual columns of the composite key each refer to their respective related table.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Primary key cf2006 BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 31st, 2006 07:21 PM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.