Re: SQL question: Find next unused number...

2004-09-15 Thread Peter J. Holzer
From: Steve Baldwin [mailto:[EMAIL PROTECTED] LOCK TABLE user_table IN EXCLUSIVE MODE ; SELECT MIN ... INSERT INTO user_table ... COMMIT ; On 2004-09-14 14:53:06 -0600, Reidy, Ron wrote: Or ... SELECT MIN(id) FROM t FOR UPDATE; Would only cause a row lock. Does that help in this

RE: SQL question: Find next unused number...

2004-09-15 Thread NIPP, SCOTT V \(SBCSI\)
(SBCSI); [EMAIL PROTECTED] Subject: RE: SQL question: Find next unused number... Or ... SELECT MIN(id) FROM t FOR UPDATE; Would only cause a row lock. - Ron Reidy Lead DBA Array BioPharma, Inc. -Original Message- From: Steve Baldwin [mailto:[EMAIL PROTECTED] Sent

Re: SQL question: Find next unused number...

2004-09-15 Thread Martin Hall
If I've understood you correctly, this might be worth a try as an example... select min(userid) from ( select userid from mhtemp a where a.userid 3000 and 0 = (select count(*) from mhtemp b where b.userid = a.userid-1) ) it survived a very quick test. Basically, the inner pair of selects

RE: SQL question: Find next unused number...

2004-09-15 Thread Reidy, Ron
. - Ron Reidy Lead DBA Array BioPharma, Inc. -Original Message- From: Peter J. Holzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 5:20 AM To: [EMAIL PROTECTED] Subject: Re: SQL question: Find next unused number... From: Steve Baldwin [mailto:[EMAIL PROTECTED

Re: SQL question: Find next unused number...

2004-09-15 Thread Ron Thomas
] Subject Re: SQL question: Find next unused number

SQL question: Find next unused number...

2004-09-14 Thread NIPP, SCOTT V \(SBCSI\)
I have a table that has a list of users with numeric user IDs. The user IDs are not sequential. There are large gaps in the list of numeric IDs. I want to pick the next unused number beginning at 3000. How do I do this? Thanks in advance. Scott Nipp Phone: (214) 858-1289

Re: SQL question: Find next unused number...

2004-09-14 Thread Tim Bunce
On Tue, Sep 14, 2004 at 02:30:43PM -0500, NIPP, SCOTT V (SBCSI) wrote: I have a table that has a list of users with numeric user IDs. The user IDs are not sequential. There are large gaps in the list of numeric IDs. I want to pick the next unused number beginning at 3000. How do I do

Re: SQL question: Find next unused number...

2004-09-14 Thread JupiterHost.Net
NIPP, SCOTT V (SBCSI) wrote: I have a table that has a list of users with numeric user IDs. The user IDs are not sequential. There are large gaps in the list of numeric IDs. I want to pick the next unused number beginning at 3000. I'd use an autoincrement column for ID so you don't have

Re: SQL question: Find next unused number...

2004-09-14 Thread Chris . R . Marbach
PROTECTED] Subject:Re: SQL question: Find next unused number... On Tue, Sep 14, 2004 at 02:30:43PM -0500, NIPP, SCOTT V (SBCSI) wrote: I have a table that has a list of users with numeric user IDs. The user IDs are not sequential. There are large gaps in the list

RE: SQL question: Find next unused number...

2004-09-14 Thread Steve Baldwin
to ensure there is an index on the user_id column if the table has a lot of rows. HTH, Steve -Original Message- From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED] Sent: Wednesday, 15 September 2004 5:31 AM To: [EMAIL PROTECTED] Subject: SQL question: Find next unused number

RE: SQL question: Find next unused number...

2004-09-14 Thread Reidy, Ron
To: 'NIPP, SCOTT V (SBCSI)'; [EMAIL PROTECTED] Subject: RE: SQL question: Find next unused number... You didn't mention what DB you are using, but if it were Oracle, I would do something like this ... SELECT MIN (user_id) + 1 FROM user_table a WHERE userid = 3000 ANDNOT EXISTS ( SELECT 0

RE: SQL question: Find next unused number...

2004-09-14 Thread Steve Baldwin
to take the hit. Steve -Original Message- From: Reidy, Ron [mailto:[EMAIL PROTECTED] Sent: Wednesday, 15 September 2004 6:43 AM To: Steve Baldwin; NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED] Subject: RE: SQL question: Find next unused number... With Oracle, this will not work with many users

RE: SQL question: Find next unused number...

2004-09-14 Thread Reidy, Ron
PROTECTED] Subject: RE: SQL question: Find next unused number... Good point Ron. However, if the requirement were to 'recycle' deleted ID's, you could obtain an exclusive lock on the table before issuing the SELECT. However, if you expect a large number of concurrent executions of this code, you

RE: SQL question: Find next unused number...

2004-09-14 Thread Steve Baldwin
] Subject: RE: SQL question: Find next unused number... Or ... SELECT MIN(id) FROM t FOR UPDATE; Would only cause a row lock. - Ron Reidy Lead DBA Array BioPharma, Inc. -Original Message- From: Steve Baldwin [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 14, 2004 2:50 PM