安卓中的数据库?
我想知道在 android 中使用数据库如何更好:有
_id integer primary key autoincrement
或没有自动增量
?
在我的应用程序中,我有两张表,一张包含列表,一张包含产品。如果我删除一个列表并且不使用自动增量
,我将执行的新列表将包含我删除的列表的产品。
这意味着,如果我在从表中删除列表时不使用自动增量,那么我也必须删除其产品。那么,哪种方法更好呢?
I want to know how it is better to work with databases in android: with
_id integer primary key autoincrement
or without autoincrement
?
In my app I have 2 tables, one with lists,and one with products. If I delete a list and I don't use autoincrement
the new list I will do will have the products of the lists I deleted.
Thats mean that if I don't use autoincrement
when I delete a list from a table, I have to delete its product too. So, which method is better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQLite 数据库表始终具有自动增量字段 rowid。
您可以参考文档:
ROWID
SQLIte db table always has autoincrement field rowid.
You can refer docs:
ROWID
Yout 列表应该有一个自动递增的
id
字段,因此您可以将它用于诸如在ListActivity
中显示它之类的事情(它使用_id
-onClick
-方法的字段)。当您删除整个列表时,不再需要它的条目(否则您不会删除整个列表),因此您也需要删除它们。如果条目也有列表的 ID(来自它们所属的列表),您也可以通过一个查询将其全部删除。
Yout lists should have a auto-incremented
id
-field, so you can use it for things like showing it in aListActivity
(which uses the_id
-field for theonClick
-method).When you delete your whole list, it's entry's are no longer needed (otherwise you wouldn't delete the whole list), so you'll want to delete them, too. If the Entry's also have the list's ID (from the list they belong to), you can delete all of them with one query, too.