0

I am playing with the HierarchyId columns in SQL Server in order to decide whether to use them in a new project.

I read some articles, watched some tutorials, I did some tests and the basic concepts are clear to me.

However, I have a problem inserting new records into the table. Let's say I have such a structure:

- Metallica (/1/)
  - Kill em all (/1/1/)
    - Hit the lights (/1/1/1/)
    - Whiplash (/1/1/3/)
- Iron Maiden (/2/)
  - Killers (/2/1/)
- Megadeth (/3/)

Imagine I want to insert a new song (Motorbreath) under Kill'em all, but I want to sort the list in alphabetical order.

So, my final list should be like this:

- Metallica (/1/)
  - Kill em all (/1/1/)
    - Hit the lights (/1/1/1/)
    - Motorbreath (/1/1/2/)
    - Whiplash (/1/1/3/)
- Iron Maiden (/2/)
  - Killers (/2/1/)
- Megadeth (/3/)

How can I achieve this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
skysurfer
  • 721
  • 2
  • 5
  • 23

0 Answers0