Ok say I have a table with two columns. Entry_id and name. Entry_id is a ROWID NOT NULL.
Essentially I just want it to increment every time something new is put in. How do i do this in the PreparedStatement. I won’t know the correct Entry_id bc it doesn’t matter. It should just increment everytime. So it would be nice if i could just insert the name into the table and entry_id increments automatically. Any idea how to do this?
Ok say I have a table with two columns. Entry_id and name. Entry_id is
Share
A ROWID is a physical address for a row in a table. It does not make sense to use a ROWID as a key– a ROWID will change over time if a table is moved from one tablespace to another, if you do an export and import, if row movement occurs, etc. And it does not make sense to increment a ROWID since the result would quite likely be invalid either in the sense that it would no longer be the physical address of an actual row or that it would not longer be a valid physical address.
If you want an auto-incrementing primary key in Oracle, you would declare the column as a NUMBER, not a ROWID. You would then create a sequence object
and reference the
NEXTVALof that sequence in yourINSERTstatementOf course, you could create a before-insert trigger to populate the primary key from the sequence
Your
INSERTstatement could then omit theENTRY_IDcolumn, letting the trigger automatically populate it.