Solved

Linked Tables

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now