title: How to SET IDENTITY_INSERT ON in SQL Server 2008 for multiple tables at once
body: <p>I have two tables <code>tblData1</code> and <code>tblData2</code> and now I want to migrate records from another table with identity insert and I am trying to run a command as shown below</p>
  
  <pre><code>SET IDENTITY_INSERT LP1.dbo.tblData1 ON
  GO
  
  SET IDENTITY_INSERT LP1.dbo.tblData2 ON
  GO
  
  INSERT INTO LP1.DBO.tblData1 (ID,DATA)
  SELECT ID,DATA FROM LP.DBO.tblData1
  GO
  
  INSERT INTO LP1.DBO.tblData2 (ID,DATA)
  SELECT ID,DATA FROM LP.DBO.tblData2
  GO
  
  SET IDENTITY_INSERT LP1.dbo.tblData1 OFF
  GO
  
  SET IDENTITY_INSERT LP1.dbo.tblData2 OFF
  GO
  </code></pre>
  
  <p>But it is showing error as below</p>
  
  <blockquote>
    <p>IDENTITY_INSERT is already ON for table 'Sample_Training.dbo.tblData1'. Cannot perform SET operation for table 'dbo.tblData2'</p>
  </blockquote>
  
  <p>Is it possible to perform multiple <code>IDENTITY_INSERT</code> at time in SQL Server 2008</p>