Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About "_id" field in Android SQLite

Tags:

android

sqlite

Is the field "_id" necessary in Android SQLite?

like image 969
Kooper Avatar asked Jul 07 '10 05:07

Kooper


Video Answer


2 Answers

_id is useful when you are using the enhanced Adapters which make use of a Cursor (e.g. ResourceCursorAdapter). It's used by these adapters to provide an ID which can be used to refer to the specific row in the table which relates the the item in whatever the adapter is being used for (e.g. a row in a ListView).

It's not necessary if you're not going to be using classes which need an _id column in a cursor, and you can also use "as _id" to make another column appear as though it's called _id in your cursor.

like image 99
Al Sutton Avatar answered Oct 03 '22 12:10

Al Sutton


Why not make use of _ROWID_?

SQLite provides this anyway for every row, so you can just alias it to _id in your select statement.

like image 26
Phil Lello Avatar answered Oct 03 '22 14:10

Phil Lello