View Full Version : mysql tables adding onto

03-11-2013, 04:31 PM
I have a simple table of ten rows.
When I want to add on ten more, one at a time, keeping things in order, do the keys adjust as the items are entered?

I use notepad++ to create the tables.
I want new item 11 to be in the item 3 spot.
Do I have to manually change each key accordingly?

If that makes no sense, sorry, just don't know how else to say it.

Old Pedant
03-11-2013, 05:42 PM
Depends on your DB design and contents.

If you mean that you have a field that just contains sequential numbers (1,2,3,etc.), then yes, you'll have to manage it all yourself.

But it's not hard.


UPDATE tablename SET idnum = -(idnum+1) WHERE idnum >= 3
INSERT INTO tablename (idnum, other, fields) VALUE(3,'other','values')
UPDATE tablename SET idnum = -idnum WHERE idnum < 0

(You can't just directily bump the numbers by one, so you make them negative at the same time you bump them and then convert all the negative numbers back.)

03-11-2013, 06:05 PM
thanks for the help. Wasn't sure how that worked.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum