Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retaining DB values as well as Dynamically generated Values.. Help Ne

Status
Not open for further replies.

rajivjha

Programmer
May 22, 2008
1
US
In my application i have a list of records coming from database (DB)

say 'Family members' of an employee

it appears on page like :

sl no. member_name relation Action
1 john son delete
2 marry daughter delete

[Add Another Family Member]

Now we have an option of dynamically adding a row

Problem :

1 . suppose I add 4 more family members till serial number 6 (2 records are already exists in database )
and then delete any one of records by clicking action delete button for corresponding row , it deletes that entry from database but also all entries that were dynamically added
also gets lost due to page reload .
how to retain the dynamically entered values ??


2 . here comes one more issue , i have a serial number column in database and employee code as PK ,
now the requirement is if any record in middle is deleted , the serial numbers must maintain order .. i.e if record having sl no 3 is deleted
the the subsquent records must be re numbered as 3,4,5 ...

How to renumber the serial numbers ?


Please do help ,

thanks
 
The second requirement is very strange. After a middle record has been deleted, the primary key of the following records have
to shift to reuse the deleted primary key.
The primary key should not be shifted like that. If there are lot of records and the time for shifting so many records will be much longer.
Shifting primary key can be a dangerous idea and it will disallow more than one user to use the application. (If two users want to delete one record, second user has to wait until the first user has finished delete and shifting)

When you are shifting the primary key and your program has exception in doing the work, you have to roll back to the state
before your program shift the primary key.
 
When you say that you the values are lost when page reloads, what kind of page is it? Is it a JSP page? You need to give little more information. You can set attributes to save the list and use that to get the dynamic values entered.

The primary key should never be adjusted. If any record is deleted then that key is lost. Adjusting the key will create referential integrity issues as well.
If you really want a number sequence then think about having another column that maintains that sequence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top