First time here? Check out the FAQ!
asked 2012-07-20 14:57:40 +0200
Say I have a table with 4 rows and the id column (primary key) has the values 1,2,3,4.
When I delete row 2, is it possible in Base to update the primary keys so that the remaining 3 rows get the id values of 1,2,3 and not 1,3,4?
answered 2013-03-06 10:50:42 +0200qubit
Hi Anon, @DonLow,
In most databases, primary key values are not shuffled around upon deletion of rows. There are a couple of reasons for doing this:
What's the use case in which you'd want to renumber all of the primary keys?
If you really need to have that kind of id in your table, instead of changing all of the primary keys, why not just put a new column "order_id" into your table. Whenever you delete a row from the table, iterate over the remaining rows (in ascending order by primary key) and set order_id to the appropriate value.
LibreOffice is made available by volunteers around the globe, backed by a charitable Foundation. Please support our efforts: Your donation helps us to deliver a better product!
Asked: 2012-07-20 14:57:40 +0200
Seen: 112 times
Last updated: Mar 06