title: How to convert nested XML into corresponding tables?
body: <p>I have a complex nested XML (generated from a C# entity graph), for example:</p>
  
  <pre><code>&lt;Customers&gt;
    &lt;Customer&gt;
      &lt;Id&gt;1&lt;/Id&gt;
      &lt;Number&gt;12345&lt;/Number&gt;
      &lt;Addresses&gt;
        &lt;Address&gt;
          &lt;Id&gt;100&lt;/Id&gt;
          &lt;Street&gt;my street &lt;/street&gt;
          &lt;city&gt;London&lt;/city&gt;
        &lt;/Address&gt;
        &lt;Address&gt;
          &lt;Id&gt;101&lt;/Id&gt;
          &lt;street&gt;my street 2&lt;/street&gt;
          &lt;city&gt;Berlin&lt;/city&gt;
        &lt;/Address&gt;
      &lt;/Addresses&gt;
      &lt;BankDetails&gt;
        &lt;BankDetail&gt;
          &lt;Id&gt;222&lt;/Id&gt;
          &lt;Iban&gt;DE8439834934939434333&lt;/Iban&gt;
        &lt;/BankDetail&gt;
        &lt;BankDetail&gt;
          &lt;Id&gt;228&lt;/Id&gt;
          &lt;Iban&gt;UK1237921391239123213&lt;/Iban&gt;
        &lt;/BankDetail&gt;
      &lt;/BankDetails&gt;
      &lt;Orders&gt;
        &lt;Order&gt;         
          &lt;OrderLine&gt;         
          &lt;/OrderLine&gt;
        &lt;/Order&gt;
      &lt;/Orders&gt;
    &lt;/Customer&gt;
  &lt;/Customers&gt;
  </code></pre>
  
  <p>Before saving the above XML data into the actual tables, I need to process it first. For this reason, I created corresponding table types. Each of these table types have an extra column (guid as ROWGUID) so that if I'm processing new data (not yet assigned primary key) I generate a unique key. I use this column to keep the relational integrity between different table types.</p>
  
  <p>What is the SQL syntax to convert the above nested XML to their corresponding tables, keeping in mind that child records must reference the generated parent guid?</p>