title: How to switch database context to newly created database?
body: <p>I wrote a script to create a database:</p>
  
  <blockquote>
    <p>1: USE master;<br>
    2: IF (db_id('myDB') is null)<br>
    3:     CREATE DATABASE myDB;<br>
    4: USE myDB;  </p>
  </blockquote>
  
  <p>but it does not work... I got an error: <strong>Could not locate entry in sysdatabases for database 'myDB'. No entry found with that name. Make sure that the name is entered correctly. (Msg <em>911</em>)</strong></p>
  
  <p>Where is my mistake?</p>
  
  <p>Thanks.</p>
  
  <p><strong>ANSWER:</strong>
  <a href="http://msdn.microsoft.com/en-us/library/ms188037.aspx" rel="nofollow noreferrer">go go go</a><br>
  <strong>USEFUL LINK:</strong> <a href="https://stackoverflow.com/q/784953/318499">Without using GO, programmatically, you would need to make 2 separate database calls.</a></p>