Solved

Linked Tables

Posted on 2004-10-20
3
162 Views
Last Modified: 2010-04-17
I am after some advice, I am developing an application which contains quite a few link tables. Here is an exmaple of such a link.

A user can be a member of multiple branches.

Thefore I have a User, Branch and UserBranch table

I have Info Classes which represent the entities such as User and Branch. Each data class returns its own set of Info entities. (Such as UsersDB class  - Method GetUsers - Returns All Users in an array of User Info's) Say I am putting on a new user, the operator can add multiple branches to a list box. I then save these by way of the users db class (is this the best way, for exmaple pass along an array of branches). However if the record has already been previously saved is it better to remove the existing entries from the link table before adding new ones.
0
Comment
Question by:rocky050371
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 12356645
I am unclear on what the question is?

Is the question:What is the best way to Update the list of branches assigned to a user?

If so:
The Delete/ReInsert method is the easiest way to implement this.  The disadvanatages are as follows:
  - Transaction may take longer(If user has 5 branches and you change 1, then 5 rows will be deleted and 5 rows will be inserted)
  - For each insert new keys will be generated.  If there are any foriegn key relationships between old data then it will be lost.

Another method is to keep a before branch list.  The user modifies the current branchlist.  The transcation code does a diff between the before branch list and the user modified branch list and builds insert/update/delete transactions.  (If the user has 5 branches and you change 1 then there will be 1 delete and 1 insert)

Another method is to use back pointers.  In other words, you already have a link in code from Users to branch.  Create a link in you class from branch to user.  To Delete a branch, null out the branch2user pointer.  Inserted branches would have null primary keys.  The transaction code would build the insert/update/delete transaction by iterating through the branch list.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Six Sigma Control Plans

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question