redbullmarky Posted May 25, 2007 Share Posted May 25, 2007 I might be missing something that makes this easier than it seems, but: If I have a DB table of categories, subcategories and items, like this: id parent_id type (category or item) name and maybe a structure like this: - Fruit [id = 1] --- Apple [id = 2, parent = 1] --- Orange [id = 3, parent = 1] --- Banana [id = 4, parent =1] - Cars [id = 5] --- Ford [id=6, parent=5] ------ something [id=10, parent=6] --- BMW [id=7, parent=5] --- Mercedes [id=8, parent=5] ------ blah [id=11, parent=8] ------ hmm [id=12, parent=8] --- Audi [id=9, parent=5] lets say that i want to duplicate an entire section (for example, Cars) including its children, giving the clone a totally new set of id's/parent_id's. i'm not really fussed about using other systems of storing tree data, so using this way - what are my options to do this? I was thinking of simply adding a number to all the keys (based on the number of the last record in the DB), but I can see how this can possibly cause issues with my ID's all over the shop. As a second question, lets say (for whatever reason) i wanted to tidy up my database - rewriting the keys from 1 to whatever with no gaps. can this be done easily? are there any special sorts of algorithms for doing something like that? Any thoughts? Cheers Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.