Article View: borland.public.cppbuilder.database.ado
Article #5215Re: Clarification on AutoInc fields
From: Umberto Uderzo
Date: Thu, 05 Jul 2001 23:30
Date: Thu, 05 Jul 2001 23:30
34 lines
2253 bytes
2253 bytes
Hello Francesco,
Ok, if your need is to obtain contiguous ids your way is sure right.
But what if the table is used by many users and the row creation process
involves much time?
You gain a lot of waiting locks...
If you can have temporary holes in your id sequence you can use the
following query:
SELECT MIN(t1.id)+1
FROM <table_name> t1
WHERE NOT EXISTS
SELECT t2.id
FROM <table_name> t2
WHERE t2.id = t1.id + 1
So if there are holes in your id sequence, the next query will fill the
first hole of the sequence.
Ciao... Umberto Uderzo
"Formentz" <francesco@leotron.com> ha scritto nel messaggio
news:3b441a9c$2_2@dnews...
> I can't see the problem with rollback the id rows, because the first
command
> I do in every query that needs a counter is to update the counters table
( I
> wrapped the insert into in a funcion that adds the right code to get the
> counter value, so if I will find a better way, I can easily change the
code
> in the function ), and so, if there are more than one queries to be
> executed, only one at a time will be executed, since the counters table is
> locked by the repeatable read transaction isolation.
> I did it so because I can't loose any numbers of the id.
Technical Details
Message-ID:
<3b44f7c5_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3b3b532b$1_2@dnews> <3B3BD2D2.5F446F35@temporaldoorway.com> <3b3c3ad2_1@dnews> <3b3c7c38_1@dnews> <3b40f10e_2@dnews> <3b441a9c$2_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,2eab2f6830ef7732 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-07-05 16:35:33 PST From: "Umberto Uderzo" <umberto@uderzo.it> Newsgroups: borland.public.cppbuilder.database.ado References: <3b3b532b$1_2@dnews> <3B3BD2D2.5F446F35@temporaldoorway.com> <3b3c3ad2_1@dnews> <3b3c7c38_1@dnews> <3b40f10e_2@dnews> <3b441a9c$2_2@dnews> Subject: Re: Clarification on AutoInc fields Date: Fri, 6 Jul 2001 01:30:17 +0200 Lines: 37 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 62.10.20.254 Message-ID: <3b44f7c5_2@dnews> X-Trace: dnews 994375621 62.10.20.254 (5 Jul 2001 16:27:01 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews