title: How - create and use database directly after creation in SQL Server?
body: <p>I created a sql script to check if a database already exist, if it already exists it deletes and re-creates.
  After I would like to <strong>connect it directly after its creation</strong> for creating tables ..</p>
  
  <p>Here is my code but it does not work.
  He announces an error message</p>
  
  <p><em><strong>Msg 911, Level 16, State 1, Line 10
  Database 'Arms2' does not exist. Make sure that the name is entered correctly.</em></strong></p>
  
  <p>My script</p>
  
  <pre><code>IF EXISTS (select * from sys.databases where name = 'Arms2')
  BEGIN 
      DROP DATABASE Arms2
      PRINT 'DROP DATABASE Arms2'
  END
      CREATE DATABASE Arms2;
      PRINT 'CREATE DATABASE Arms2'
  
  USE Arms2
  
  CREATE TABLE .....
  </code></pre>