Is the "Row ID" equal to the primary key?

Asked

Viewed 181 times

7

The function Insert of Android returns a row ID according to the documentation,

the Row ID of the Newly inserted Row, or -1 if an error occurred

To row ID corresponds to the primary key, ID, if there is?

  • 1

    It is a unique key, but not the primary one. Perhaps the id is eventually updated, even if the data itself is the same. When it occurs? INSERT OR REPLACE, the id ends up being replaced after this operation

1 answer

7


In some situations, yes.

The PRIMARY KEY of a rowid table (if there is one) is usually not the true Primary key for the table, in the sense that it is not the Unique key used by the underlying B-Tree Storage engine. The Exception to this Rule is when the rowid table declares an INTEGER PRIMARY KEY. In the Exception, the INTEGER PRIMARY KEY Becomes an alias for the rowid.

Source.

The PRIMARY key of a rowid table (if there is one) is usually not the true primary key for the table, as it is not the unique key used by the underlying B-Tree storage mechanism. The exception to this rule is when the rowid table declares a PRIMARY KEY INTEGER. In the exception, the PRIMARY KEY INTEGER becomes an alias for rowid.

So your modeling can make this true or not. What is recommended to do so most of the time.

Useful too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.