Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Handling a list data structure

Author  Topic 

mpv55
Starting Member

1 Post

Posted - 2011-09-11 : 15:03:08
I am new in using SQL server, even creating a database. So, I may not be using correct terminology.

I need to create two tables (first table, "Branches" with fields (say BranchID, branchName) and second table, "components" with fields (say componentID, ComponentName, BranchID,.....). The BranchID is assigned as a foreign key.

In my application I need to get all the components in a branch in the same order as stored. I was thinking to handle it with creating a field (ComponentIndexInBanch) in the component table for indexing the order (say 1, 2, 3,.. ) for the components. But there is a problem if I have to delete or insert some components in-between. Then I have to update the field (ComponentIndexInBanch) for all the corresponding records each time.

I was searching for this problem on internet. I found that it can be handled with a "linked list" instead of array. I have no idea how to create a data table for it.

I do appreciate your help in solving this problem. If there is some other approach for handling it, please let me know.

Thanks




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-12 : 00:58:32
why should you need a separate ComponentIndexInBanch field? If you've created the table Components in such a way that componentID is unique and auto incrementing it will take care of itself. while retrieving you just need to add ORDER BY BranchID,componentID ASC to make sure you retrieve the components in order of insertion for each of branches.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -