If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Suggestion about row deletion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-06, 11:21
hYph3n hYph3n is offline
Registered User
 
Join Date: Jul 2006
Posts: 26
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
Reply With Quote
  #2 (permalink)  
Old 08-18-06, 13:24
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
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.
Reply With Quote
  #3 (permalink)  
Old 08-23-06, 07:12
hYph3n hYph3n is offline
Registered User
 
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 ?
Reply With Quote
  #4 (permalink)  
Old 08-24-06, 06:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On