Creating Relationships Between Tables

When you created the two tables in the preceding section, you added an integer field called _id that was marked as a primary key. Primary keys uniquely identify a row in a table; no two rows will have the same value. The autoincrement functionality that you used is a convenient way of making sure that the IDs are unique. Note that the IDs themselves are unique only in the table, and not across the entire database. Thus, rows in separate tables may have the same ID.

Although the ID will generally increment by 1, they may not always do so, so don’t assume this is necessarily the case in your code.

If you do not create your own primary key, SQLite will create one for you having the name _id.

Keys don’t have ...

Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.