title: Create database if db not exist
body: <p>I want to make <code>SQL Server</code> scritp for creating database if not exist.</p>
  
  <pre><code>IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'DataBase')
    BEGIN
      CREATE DATABASE DataBase
  
      USE DataBase
  
      CREATE TABLE TableName (
          Id INT PRIMARY KEY IDENTITY (1, 1),
          Name VARCHAR(100)
      )
  
      --more tables here
      --some procedures here too
  
    END
  </code></pre>
  
  <p>From code above i getting this error:</p>
  
  <blockquote>
    <p>Msg 911, Level 16, State 1, Line 5
    Database 'DataBase' does not exist. Make sure that the name is entered correctly.</p>
  </blockquote>
  
  <p>How to make database with tables and procedures when database not exist? I want to make it in one query</p>