title: Create multiple views inside a schema - SQL Server
body: <p>How can I create multiple views inside the <code>CREATE SCHEMA</code> statement?</p>
  
  <p>I want to create a <code>SCHEMA</code>, and create two views inside it in the same statement, so all those statements work as a one unit? Succeed or fail together!</p>
  
  <p>From MSDN: <a href="http://msdn.microsoft.com/en-us/library/ms189462.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms189462.aspx</a></p>
  
  <blockquote>
    <p>"CREATE SCHEMA can create a schema, the tables and views it contains,
    and GRANT, REVOKE, or DENY permissions on any securable in a single
    statement. CREATE SCHEMA transactions are atomic. If any error occurs
    during the execution of a CREATE SCHEMA statement, none of the
    specified securables are created and no permissions are granted."</p>
  </blockquote>
  
  <p>,</p>
  
  <p>How can I do this? I tried this:</p>
  
  <pre><code>CREATE SCHEMA [MYSCHEMA] AUTHORIZATION [dbo]
      CREATE VIEW [VIEW1]
      AS 
          SELECT [ID]
                 ,[NAME]
                  FROM [dbo].[TABLE1]
          /* Here is the Problem */
          GO
  
          CREATE VIEW [VIEW2]
          AS
          SELECT [ID]
                 ,[NAME]
                  FROM [dbo].[TABLE2]
          GO
  </code></pre>
  
  <p>If I include a <code>GO</code> statement just after first view creation, then script runs but second view <code>VIEW2</code> is created under the <code>dbo</code> schema, not under <code>MYSCHEMA</code>, and doesn't run as a single unit either.</p>
  
  <p>If I remove the <code>GO</code> after the first view, then it gives an error saying </p>
  
  <blockquote>
    <p><em>CREATE VIEW must be the first statement of a batch</em></p>
  </blockquote>
  
  <p>for the second <code>CREATE VIEW</code> statement.</p>
  
  <p>How do I solve this and create both views as a part of <code>CREATE SCHEMA</code> statement?</p>