1

I created a new table in SQLite, and named one of the columns as 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?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Rahul Mandaliya
  • 728
  • 1
  • 12
  • 36

1 Answers1

2

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

_id INTEGER PRIMARY KEY AUTOINCREMENT

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


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

From this source (direct quote)

Ribose
  • 2,213
  • 15
  • 22