Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:50+00:00 2026-06-15T14:33:50+00:00

How can I create multiple views inside the CREATE SCHEMA statement? I want to

  • 0

How can I create multiple views inside the CREATE SCHEMA statement?

I want to create a SCHEMA, and create two views inside it in the same statement, so all those statements work as a one unit? Succeed or fail together!

From MSDN: http://msdn.microsoft.com/en-us/library/ms189462.aspx

“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.”

,

How can I do this? I tried this:

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

If I include a GO statement just after first view creation, then script runs but second view VIEW2 is created under the dbo schema, not under MYSCHEMA, and doesn’t run as a single unit either.

If I remove the GO after the first view, then it gives an error saying

CREATE VIEW must be the first statement of a batch

for the second CREATE VIEW statement.

How do I solve this and create both views as a part of CREATE SCHEMA statement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:33:51+00:00Added an answer on June 15, 2026 at 2:33 pm
    CREATE SCHEMA [MYSCHEMA] AUTHORIZATION [dbo]
    
    CREATE VIEW [VIEW1] AS SELECT [ID], [NAME] FROM [dbo].[TABLE1]
    CREATE VIEW [VIEW2] AS SELECT [ID], [NAME] FROM [dbo].[TABLE2]
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Clearcase I can create multiple views and work on 3-4 defects simultaneously. Is
How can I create multiple dropdowns in my view with values coming from my
Can we create multiple schemas for a particular user? I am currently logged in
I'll start by quoting google's blog Project owners can now create multiple repositories for
I am building a website templating system where multiple user can create their own
I would like to create a class whose methods can be called from multiple
I was wondering, when you create an object you can often set multiple attributes
I can create and use dynamic two dimensional array in Fortran (in 77 standard).
I have multiple views that come and go as the application runs. I want
I have over 30 clickable imagebutton views that I want to create programatically instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.