Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B536010AA4 for ; Mon, 17 Mar 2014 08:49:57 +0000 (UTC) Received: (qmail 68940 invoked by uid 500); 17 Mar 2014 08:49:57 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 68526 invoked by uid 500); 17 Mar 2014 08:49:55 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 68514 invoked by uid 99); 17 Mar 2014 08:49:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 08:49:53 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Dyre.Tjeldvoll@oracle.com designates 141.146.126.69 as permitted sender) Received: from [141.146.126.69] (HELO aserp1040.oracle.com) (141.146.126.69) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Mar 2014 08:49:46 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s2H8nPIE025882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 17 Mar 2014 08:49:25 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2H8nO9n011033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 17 Mar 2014 08:49:24 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2H8nNS3014587 for ; Mon, 17 Mar 2014 08:49:24 GMT Received: from atum20.no.oracle.com (/10.172.139.200) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Mar 2014 01:49:23 -0700 Message-ID: <5326B712.7030601@oracle.com> Date: Mon, 17 Mar 2014 09:49:22 +0100 From: Dyre Tjeldvoll Organization: Oracle User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: derby-user@db.apache.org Subject: Re: Adding a new record to a table References: <1394992481692-138004.post@n7.nabble.com> In-Reply-To: <1394992481692-138004.post@n7.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-Virus-Checked: Checked by ClamAV on apache.org 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