Results 1 to 3 of 3

Thread: Inserting records when linked (associate) tables are involved?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    4

    Question

    I am using SQL Server, VisualBasic 6.0 (ActiveX DLL components), MTS, and ASP for a web community development project. Here's my problem: I have a members table, an addresses table, and a linking table called MembersAddresses. This way my data is fully normalized. A member can have more than one address and one address can be linked to more than one member. How do I write a routine (in a VB Class Module) which will insert a new address and insert a new record in the MemberAddresses table to link the new address to the appropiate member who owns the address? In other words the new address needs a corresponding new record in the MemberAddresses table so it can be linked to a member.

    Here are the tables:

    Members
    ---------
    MemberID
    Name
    Email
    etc...

    Addresses
    -----------
    AddressID
    Address
    City
    etc...

    MembersAddresses
    ------------------
    MembersAddressesID
    MemberID
    AddressID

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Use 3 separate SQL insert commands, wrapped inside of a transaction. This will ensure integrity

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    4

    Reply

    Cool. Someone else also gave me the idea that @@IDENTITY would work to pull the AddressID and I think they're right.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width