删除行重组后的数据库 [英] Restructuring the database after deleting a row

查看:164
本文介绍了删除行重组后的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有我的屏幕上了几个编号EditTexts。这些都是对的retreival所示
从数据库中的信息。但我的onLongClickListener()是删除特定的EditText。发生这种情况,并且在同一反映在数据库中。然而w.r.t条目的数字是要被更新

 >例如: - 
>我有4 EditTexts ....
I标记删除第二个....
>将数据库的编号为1,3,4 ...
>我现在希望它被重新编号为1,2,3。我可以用什么逻辑?


解决方案

您可以跟踪被删除的号码,然后执行:

 更新Ť
    设置NUM = NUM​​-1
    其中num> < VAL删除>

您必须设置与刚刚删除值查询。但这导致更新很多很多行,所以它可能不是一个好主意。

So, I have a few numbered EditTexts on my screen. These are shown upon retreival of info from the database. But my onLongClickListener() is to delete a particular EditText. This happens and the same is reflected in the database. However the numbers w.r.t the entry is to be updated.

>Eg:-   
>I have 4 EditTexts....
>I delete the second one....
>The database is numbered 1,3,4...
>I now want it to be renumbered as 1,2,3.

What logic may I use? 

解决方案

You could keep track of the number that was deleted, and then do:

update t
    set num = num-1
    where num > <val deleted>

You have to set up the query with the just deleted value. This does result in updating many, many rows, so it may not be a good idea.

这篇关于删除行重组后的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆