为什么有必要进行重命名数据库表ID来_id? [英] Why is it necessary for database table id to be renamed to _id?

查看:507
本文介绍了为什么有必要进行重命名数据库表ID来_id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我SQLite中创建一个新表,并命名为列之一为 ID

I created a new table in SQLite, and named one of the columns as id.

当我在运行时访问该数据库,它会产生一个错误。我发现,在我的数据库,我必须使用 _id 而不是的id 。为什么是必要的此列被命名为 _id

When I access that database at runtime, it generates an error. I found that in my database, I have to use _id instead of id. Why is it necessary for this column to be named as _id?

推荐答案

它总是声明主键作为一个好主意:

It's always a good idea to declare your primary key as:

_id INTEGER PRIMARY KEY AUTOINCREMENT

这样的话,Android的功能,它可以使用 _id 来使某些事情的工作例如ID的一个的CursorAdapter

That way, Android's functions, which could use the _id to make certain things work for example the id's in a CursorAdapter.

有关你应该总是使用标识符_id一些Android的功能依赖于这个标准的数据库的主键。

For the primary key of the database you should always use the identifier "_id" as some of Android functions rely on this standard.

从这个源(直接引用)

这篇关于为什么有必要进行重命名数据库表ID来_id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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