Very nice question, definately learned something today.
Got it wrong, because the BOL page about CREATE SCHEMA didn't mention anything about batches.
It doesn't really stand out, but the information is
This statement must be executed as a separate batch.
Nice question, Richard - I almost fell for it; I was saved by the feeling of "it can't be that simple, let's look a bit further". (That being said, I always forget which statements must run in seperate batches, so I very often get errors because of that).
Oh, one final remark - if I should copy and paste your script in SSMS and execute it, I would actually get a different error: "Could not locate entry in sysdatabases for database 'TempDB'. No entry found with that name. Make sure that the name is entered correctly."
On a server with a case sensitive collation, database names are case sensitive as well. You should use all lower case for the system databases tempdb, system, model, and msdb.
Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis