title: Insert data to Master and Detail table at the single script with multi-data using T-SQL
body: <p>I've to insert data to Master and Detail records, however what can I do if I need to insert both data at the single script with T-SQL.<br>
  Question<br>
  1.How can I get the Master Index Key(Identity increment) when data's was inserted<br>
  2.and then get Index Key to Detail record at the same time(in single script)    </p>
  
  <blockquote>
    <p>For example(hopefully result):</p>
  </blockquote>
  
  <p>Master table<br>
  <a href="https://i.stack.imgur.com/ObMDN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ObMDN.png" alt="enter image description here"></a><br>
  Detail table<br>
  <a href="https://i.stack.imgur.com/2NrY1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2NrY1.png" alt="enter image description here"></a></p>
  
  <p>the column "SeatMasterIndexID" data is from Master "IndexID" </p>
  
  <blockquote>
    <p>PS: pseudocode</p>
  </blockquote>
  
  <pre><code>INSERT INTO MasterTable (TeamId ,  BranchId , SeatId) OUTPUT Inserted.IndexID ......
  INSERT INTO DetailTable (TeamId ,MasterIndexID) values('1',Inserted.IndexID &lt;-- from output Inserted.IndexID)
  </code></pre>