Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    26

    Unanswered: Suggestion about row deletion

    Hi,

    There is always problem that when we create keys and on deletion of those keys we get jumps in the keys. like if i am having a database of 15 values with PK values from 1-15. Now suppose i have deleted a few rows, those keys will be deleted.

    Now when ever i insert new row, i'll use new value onward from 15, we dont use those delelted values. That can create our db with sparce keys ... :-s ... what should i do, how to overcome it?

    thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    You should do nothing about it.
    I assume this PK is actually an artificial PK and not a real one. Especially in that case you (or your application) should never rely on any "ordering" or implicit logic in the primary key. If you do, re-think your design.

  3. #3
    Join Date
    Jul 2006
    Posts
    26
    is there any way that i can make function which return a value for the next PK of a particular table ?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by hYph3n
    is there any way that i can make function which return a value for the next PK of a particular table ?
    there is, but i cannot tell you because i think what you are trying to do is wrong

    as shammat suggested, do not mess around with auto_increment numbers

    let the database assign them, and then leave them alone

    if you need the PK of a row, get it after insertion using the LAST_INSERT_ID function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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