People that think this is a good solution aren't "enterprise" developers
anyway! :)

Though I sympathize with your pain, Sybase has identity columns, which
work quite well.

The other option is to simply have a table to like (sequence varchar, id
int) and then:

update sequences set id = id + 1 where sequence = 'mytable';
-- that also locked the row for the next updater, so now it is perfectly
safe to do:
select id from sequences where sequence = 'mytable'

All you need to do is spent half an hour at the start of a project setting
up this, a stored proc and a Tcl procedure named "get_next_id" and forget
about it from then on...

Other than this quirk, I have found Sybase to be much more "enterprise"
than other database I have worked with.

Cheers,
Bas.

Mark Aufflick said:
> How depresssing. I'm doing a lot of work with Sybase these days.
> That's right, the "enterprise" database. It seems that sequences are
> not "enterprise" enough and you end up seeing developers resorting to
> stuff like this instead.
>
> Not that it's relevant in this case, but it's nice to blowoff steam
> occasionally - especially in an environment where people get it!
>
> On 3/29/06, Bas Scheffers <[EMAIL PROTECTED]> wrote:
> > William Scott Jordan said:
> > > ns_db dml $db "INSERT INTO test (test_column) SELECT
> > > COALESCE(MAX(test_column),0) + 1 FROM test"
> > Ehrm, that is a very, very bad way of creating keys. It is no unlikely
> > that on a very loaded site two people might insert at the same time and
> > get the same key!
> >
> > The correct way of doing this is using a sequence:
>
>
> --
> AOLserver - http://www.aolserver.com/
>
> To Remove yourself from this list, simply send an email to
> <[EMAIL PROTECTED]> with the
> body of "SIGNOFF AOLSERVER" in the email message. You can leave the
> Subject: field of your email blank.
>


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to