Solved

Linked Tables

Posted on 2004-10-20
3
158 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now