Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a one table like userid,username, activestatus these are column names. But i want to delete from this table for 1 row that is middle of the table, then the next row will be replaced in the same deleted record userid.

hope this clear...

please help on this....

Regards
Ram
Posted
Updated 3-Nov-13 22:50pm
v2

Generally speaking, you can't - it would mean that UserIDs would have to percolate down through the system and potentially that would have to be reflected in other tables - they would use Foreign keys to relate the info in that table to a specific user and just "moving" the UserID in you main table would cause the wrong data to be associated.

There is also the problem that SQL doesn't really have a concept of "next" record as such - it can assign row numbers to records for a particular sort order, but there is no intrinsic "next" or "previous" record (and no way to access them if there was)

And to make matters worse, what happens if two users delete a row in quick succession? It will take very careful management to ensure that the right row is deleted in each case.

Instead, use a "dummy" userID which is related to the RowNumber in a particular sort order. Or better still - live with gaps. It's a much less confusing situation for everybody!
 
Share this answer
 
If I got you, the operation you intend to do is an UPDATE [^] that is you want to change the useraname and activestatus values in a row having the given userid.
e.g.
SQL
UPDATE mytable SET username='NewUsername', activestatus='Y' WHERE userid='foo'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900