You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bob M <rg...@orcon.net.nz> on 2014/03/16 18:54:41 UTC
Adding a new record to a table
On a regular basis I add a new record and delete the oldest record in my
table
The records have a key and up until recently were listed by date/time order
as I wish to have them
I understand that this is unnecessary but it is great to always find the
latest records at the end of the table
Now, after a tweek in the code, my newest records are being written at the
beginning of the table next to the oldest records ?????
What code do I need to add, so that when any new record is added, it will
appear at the end of the table and not at the beginning ?
Thanks
Bob M
--
View this message in context: http://apache-database.10148.n7.nabble.com/Adding-a-new-record-to-a-table-tp138004.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Adding a new record to a table
Posted by Dyre Tjeldvoll <Dy...@oracle.com>.
On 03/16/2014 06:54 PM, Bob M wrote:
> On a regular basis I add a new record and delete the oldest record in my
> table
> The records have a key and up until recently were listed by date/time order
> as I wish to have them
>
> I understand that this is unnecessary but it is great to always find the
> latest records at the end of the table
>
> Now, after a tweek in the code, my newest records are being written at the
> beginning of the table next to the oldest records ?????
>
> What code do I need to add, so that when any new record is added, it will
> appear at the end of the table and not at the beginning ?
At the risk of sounding somewhat pedantic: A database table is NOT an
array on disk. You do NOT control where (physically) your records end
up. The order in which you SEE records is determined by the ORDER BY
clause you use for your query.
If you don't specify an ORDER BY clause it may appear that the order is
predictable and that it corresponds to the chronological order in which
records were inserted, but this is merely a coincidence, and cannot be
relied upon.
Derby does not, unlike some other databases, automatically add a rowid
column to your table that is always increased when adding records to the
table. You can create such a column manually - see
https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/ref/index.html
--
Regards,
Dyre