title: How can I insert unique HierarchyId path without having to specify left and right sibling?
body: <p>I am using HierarchyId in SQL to store the data. I am following the tutorial  from here:</p>
  
  <p><a href="http://www.codeproject.com/Tips/740553/Hierarchy-ID-in-SQL-Server" rel="nofollow">http://www.codeproject.com/Tips/740553/Hierarchy-ID-in-SQL-Server</a></p>
  
  <p>The examples that are mentioned in the sample are explicitly specifying  position of the node:</p>
  
  <pre><code>DECLARE @parent HierarchyId = (SELECT Node FROM H WHERE Name = 'Thuru')
  DECLARE @jhony HierarchyId = (SELECT Node FROM H WHERE name = 'Johnny')
  INSERT INTO H (Node,ID,Name) VALUES (@parent.GetDescendant(@jhony,NULL), 3, 'Robert') 
  </code></pre>
  
  <p>Code is telling SQl that which are the sibling nodes of this particular Node. Which is OK. However, I all I want is that insert node at ANY position in the tree under a PARTICULAR parent. which means I want to be able to use something like:</p>
  
  <pre><code>DECLARE @parent HierarchyId = HierarchyId::GetRoot()
  INSERT INTO H (Node,ID,Name) VALUES (@parent.GetDescendant(NULL,NULL),2,'Johnny') 
  </code></pre>
  
  <p>WHich means</p>
  
  <ul>
  <li>As far as the node is inserted under a correct parent, we do not care about the horizontal positioning of the node</li>
  <li>When I tried GetDescendant(NULL,NULL) for multiple inserts for the same parent, it gives the same path /1/ to every child. Why is that?</li>
  <li>Also, I came across following link: <a href="https://technet.microsoft.com/en-us/library/bb677212%28v=sql.105%29.aspx" rel="nofollow">https://technet.microsoft.com/en-us/library/bb677212%28v=sql.105%29.aspx</a>. which is showing an example of storing the last inserted child for a particular parent and then use it as a reference before inserting doing any further inserts into the DB. Is it the standart method for doing insert into a table with hierarchy to get the uniqueness in the path?</li>
  </ul>