Id in SQLite database tables

johnaaronrose

Active Member
Licensed User
Longtime User
I noted from the B4a User's Guide that the example tables have ID as the Primary Key. I seem to remember reading seeing somewhere that SQLite tables always have a hidden column of _id which will act as the Primary Key if none is specified. I also remember reading somewhere else that it is recommended that Android database tables should be defined with _id as the Primary Key. Can anybody resolve this apparent contradiction (i.e. whether to use _id or ID or Id)?

I also noted from the B4a User's Guide that the examples us REAL (rather than FLOAT) for a column type. Is this recommended for Android/B4a?
 

Informatix

Expert
Licensed User
Longtime User
I noted from the B4a User's Guide that the example tables have ID as the Primary Key. I seem to remember reading seeing somewhere that SQLite tables always have a hidden column of _id which will act as the Primary Key if none is specified. I also remember reading somewhere else that it is recommended that Android database tables should be defined with _id as the Primary Key. Can anybody resolve this apparent contradiction (i.e. whether to use _id or ID or Id)?

I also noted from the B4a User's Guide that the examples us REAL (rather than FLOAT) for a column type. Is this recommended for Android/B4a?

All databases store an unique ID for each row. That's mandatory for their internal use, but this ID is not always public. In SQlite, it is called rowid and is safe to use AFAIK (it can even be faster than your own ID) but you cannot use it in a foreign key constraint as the parent key.

The only types that SQlite knows are:
TEXT
INTEGER
REAL
BLOB
All other types are just aliases.
 
Upvote 0
Top