Create Schema Syntax Error

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).





MariaHaltAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
try this:

USE tempdb;
GO
CREATE SCHEMA smithj AUTHORIZATION smithj
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MariaHaltAuthor Commented:
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
MariaHaltAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.