sc_king
02-14-2008, 01:26 AM
How can insert data between 2 rows where id is the primary key and auto_incremented.
I don't want to insert it at the bottom, unless I have to.
I don't want to insert it at the bottom, unless I have to.
|
Click to See Complete Forum and Search --> : [RESOLVED] Inserting data between rows in MYSQL sc_king 02-14-2008, 01:26 AM How can insert data between 2 rows where id is the primary key and auto_incremented. I don't want to insert it at the bottom, unless I have to. chazzy 02-14-2008, 11:51 AM I'm not sure what you mean. You're saying you deleted, for example id 6, and now want to add it back? sc_king 02-20-2008, 01:00 AM For example: id name 1 a 2 b 3 c 4 d Is there a way to insert a new row between id 2 and 3 and shift id 3 and 4 to 4 and 5? id name 1 a 2 b 3 new 4 c 5 d Nedals 02-20-2008, 02:48 AM The simple answer is No. Auto-increment will not allow you to do that. You could, however, create some addition code to exchange the values. ie: Get value3 at id=3; update with 'new' at id=3 Get value4 at id=4; update with value3 at id=4 etc, Finally insert value5. (in your example) Looks complicated, but a simple loop of code will do the job. Even without auto-increment you would still have to do something like this. sc_king 02-21-2008, 02:50 AM ok thanks!, just making sure there wasn't a simpler way. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |