pikemsu28 Posted December 21, 2006 Share Posted December 21, 2006 Is it possible to insert a record into the middle of a table allowing the auto inc id to adjust accordingly? example:Table: Color Schemesid(auto inc) value 1 value 21 Red Blue2 Blue Green3 Orange Black4 Black RedTable: Color Schemes (I need to insert a record between records 2 and 3)id(auto inc) value 1 value 21 Red Blue2 Blue Green3 Green Orange (inserted record and causes ID of following records to change)4 Orange Black5 Black RedI hope this makes sense.Thanks,Jason**Thanks to who all replied. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 21, 2006 Share Posted December 21, 2006 I want to say no, just because you shouldn't. Auto inc PK's aren't meant to be used like this. You could do this on the one table but it would mess up every table in your database that uses that id as a foreign key. Use instead a separate field, I usually call mine sort_order for that.Then before the insert:[code]UPDATE color_schemes SET sort_order = sort_order + 1 WHERE sort_order > 2[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted December 22, 2006 Share Posted December 22, 2006 There's no such thing as the "middle" of a table.. that's the first problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.