title: Write script to Migrate data from one database to another in SQL
body: <p>I want to migrate data from one database to another. I have written my sql statements to do so. However, the issue I a, facing is, I need to "use databasename GO" before executing the query (Can I fire use B and A at the same time to run my script?). Below is my query.</p>
  
  <pre><code>Use B GO
  Use A GO
  
  IF NOT EXISTS (select 1 FROM B.INFORMATION_SCHEMA.TABLES where table_schema = 'dbo' and table_name = 'Animal')
      BEGIN
          PRINT 'Table does not exist'
          RETURN
      END
  GO
  
  IF NOT EXISTS (select 1 FROM B.INFORMATION_SCHEMA.TABLES where table_schema = 'dbo' and table_name = 'Animal')
      BEGIN
          PRINT 'Table does not exist'
          RETURN
      END 
   GO
  
  
  SET IDENTITY_INSERT B.[dbo].Animal ON GO
  
  INSERT INTO B.[dbo].Animal
  (Id, Name)
  SELECT (Id, Name)
  From A.dbo.Animal
  
  GO
  
  SET IDENTITY_INSERT B.[dbo].Animal OFF 
  GO
  </code></pre>
  
  <p>Would this work to move the data?</p>