Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create Schema Syntax Error

Posted on 2008-11-10
3
Medium Priority
?
1,085 Views
Last Modified: 2012-05-05
Getting '' 'CREATE SCHEMA' must be the first statement in a query batch" error when executing the following statement.  

USE tempdb;
CREATE SCHEMA smithj AUTHORIZATION smithj

I've checked it a dozen times against the example provided in SQL Server 2005 Books Online for Create Schema.  It looks just like it, so I don't understand why I'm getting this error.   (FYI, I can run the second line on its own without errorring).





0
Comment
Question by:MariaHalt
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 2000 total points
ID: 22923255
try this:

USE tempdb;
GO
CREATE SCHEMA smithj AUTHORIZATION smithj
0
 

Author Comment

by:MariaHalt
ID: 22923314
Yes, that works b/c it's executing 2 commands.  I need to execute one command...let me explain...it's part of the following statement that I'm sending to sql server from a vb app (I simplified it to ask the question):

IF NOT EXISTS (SELECT * FROM tempdb.sys.schemas WHERE name = 'smithj')
BEGIN
      USE tempdb
      CREATE SCHEMA vandette AUTHORIZATION vandette
END

Again, it's just like the example on line.
0
 

Author Comment

by:MariaHalt
ID: 22923333
Oops!  Typo...the previous comment should read as follows:

Yes, that works b/c it's executing 2 commands.  I need to execute one command...let me explain...it's part of the following statement that I'm sending to sql server from a vb app (I simplified it to ask the question):

IF NOT EXISTS (SELECT * FROM tempdb.sys.schemas WHERE name = 'smithj')
BEGIN
      USE tempdb
      CREATE SCHEMA smithj AUTHORIZATION smithj
END

Again, it's just like the example on line.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question