Re: Rowid Question
Posted in 1992
In article <1992Sep28.113926.5782@bnr.ca> writes: >Rory Martin wrote: >> >> > My simple question is: >> > >> > If you 'load' a new table from a previously 'unloaded' file >> > are the rowids always reassigned sequentially starting with 1? (i.e., >> > each added record will have rowid numbers 1,2,3,4,...,n). >> > >> >> The simple answer is...yes. Rowids are simply physical positions within >> the table. They have no other relationship with a record. They are also >> reassigned within the same table if a record has been deleted and another >> inserted. > > Rowid are not automatically reassigned. You can reassign them, but only >manually. I'm afraid this last item is inaccurate. Rowids are not "assigned" either manually or automatically, though "automatically" is closer to the truth. It is correct that rowids represent the physical location of a row. WIth SE, it represents the offset of rows into the .dat file where the row can be found. With OnLine, it is a bitmapped value made up of a page number and slot number. The point here is that, as far as the data is concerned, a rowid is never "assigned"; the data acquires a rowid when it is inserted into the table. This rowid would be stored in an index if one exists on a table - it acts as the pointer to the row. Rowids can be reassigned, in a sense, by deleting a row and then inserting a new row. The new row is likely going to wind up in the location vacated by the deleted row. It would then have the same rowid as the deleted row. There is no way to guarantee that a row have a particular rowid (though you can be clever enough to get it to happen in most cases). It is a very bad idea to use rowids as keys in an Informix database for the reason that they are reused. Since a rowid is a location value, you are really violating the relational rules by using it to connect tables. You are much better off using a serial field, which is stored as a real column in the row, and is independent of location. Dave -- Disclaimer: These opinions are not those of Informix Software, Inc. ************************************************************************** The heart and the mind on a parallel course, never the two shall meet. -E. Saliers