SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to retrive next id

    Which is the beter way to retrieve from a table the next primary key id which is NOT using auto-incremented?

    - use something like "select max(id)"

    - use another sequential table (which is common in most of the database abstraction layer scripts)

    thanks in advance
    Last edited by okazu; Oct 4, 2001 at 18:13.
    http://www.mywebaddons.com/

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if your making id's that always go up sequentially, you can use max. And it'll take the largest number.
    Or you could just sort them with order by column_name DESC and it'll sort the numbers starting with the highest. so just take the first entry that your query returns ant that'll be the highest id.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I think that's the easiest way, but why do most of the abstract database layer scripts use another sequential table for this?
    I know that if you use a sequential table, you will not reuse a deleted id, which helps avoiding data relation inconsistencies, but is this the only reason they use the sequential table? Doesnt that affect the performance?
    http://www.mywebaddons.com/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •