PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Jay Listo <jay dot listo at gmail dot com>
Subject: Re: Probably Trivial: Finding Largest Primary Key used in Table
Date: Jul 1 2005 10:07AM

Thanks Michael and Darin,

For the purposes of a few code tables (which would be used for lookups 
mainly)...I'll probably just need MAX(primary_key_col) + 1


Delegal, Darin wrote:

>If you are dealing with an algorithmically assigned key, it's fairly
>easy. The following statement just assumes you want to use the max value
>plus one.
>
>SELECT new_key_value = MAX(primary_key_col) + 1
>FROM table
>
>Then INSET the new record using the new_key_value returned from the
>SELECT.
>
>If you are not using an algorithmically assigned key, then we'll need
>more information to help you.
>
>Darin Delegal
>'When the customer demands the impossible, they will end
>up buying from the guy who offers them the impossible.
>And the results, though tragic, are sadly predictable.' - Robert A.
>Heinlein
>
>-----Original Message-----
>From: owner-sybperl-l@peppler.org [mailto:owner-sybperl-l@peppler.org]
>On Behalf Of Jay Listo
>Sent: Thursday, June 30, 2005 7:16 AM
>To: sybperl-l@peppler.org
>Subject: Probably Trivial: Finding Largest Primary Key used in Table
>
>Hi All,
>
>This may sound trivial...but I've been trying to find out how to find
>the largest primary key that's been assigned/used within a table.
>
>I'm new to DB development while I have done some DBA.
>
>It would save me trouble when I want to keep control of the primary
>keys, make sure that when I insert a new record I can assign a unique
>primary key.
>
>I would like to do this using a perl script...not as some stored
>procedure or constraint so as to keep it as DB independent (regardless
>of Sybase, MySQL, Oracle, etc) as possible.
>
>Best Regards,
>Jay
>
>  
>