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,738
  • 21
  • 105
  • 131
Rahul Mandaliya
  • 738
  • 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,223
  • 16
  • 22