Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Inserting Primary Keys


Message #1 by "Mitten Shah" <mittenshah@h...> on Mon, 20 Aug 2001 02:53:42 +0000
Hello everyone, I want to insert primary keys from two tables into one 

table that acts as a link between both of these tables. These tables are 

Author,Writes and Article. Now an Author can write many Articles and vice 

versa. Now what i want to do is that, for example AuthorID = 1 and 

Article=1, and also AuthorID = 2 and ArticleID = 2. How can i do this? Can 

anyone please help me out. And i would like to say the ID's of both tables 

are generated via an AutoNumber Key.



 



Thanks



 



Mitten



Message #2 by Hal Levy <hal.levy@s...> on Mon, 20 Aug 2001 11:51:16 -0400
You have a Many to Many relationship which requires a table in between to

track the relationship





t_ArticleAuthor

---------------

Article_ID

Author_ID





SP_InsertArticle (psuedo code)

-----------------

set nocount on

Insert Into Articles..

set nocount off

select @identity (this is the PKid)



SP_AttachAuthors (pseudo code)

----------------

Insert into Authors Article_ID, Author_ID





Call SP_InsertArticle once

Call SP_AttachAuthors for each author you need to attach to an article.





Hope that helps.



Hal Levy

StarMedia Network, Inc.

Intranet Development Manager



> -----Original Message-----

> From: Mitten Shah [mailto:mittenshah@h...]

> Sent: Monday, August 20, 2001 5:59 AM

> To: ASP Databases

> Subject: [asp_databases] Inserting Primary Keys

>

>

> Hello everyone, I want to insert primary keys from two tables into one

> table that acts as a link between both of these tables. These tables are

> Author,Writes and Article. Now an Author can write many Articles and vice

> versa. Now what i want to do is that, for example AuthorID = 1 and

> Article=1, and also AuthorID = 2 and ArticleID = 2. How can i do this? 

> Can anyone please help me out. And i would like to say the ID's of both 

> tables are generated via an AutoNumber Key.

>

>

>

> Thanks

>

> Mitten




  Return to Index