vrijdag 25 maart 2011

T-SQL the simple things: CREATE SCHEMA Must be the only statement in the batch

When creating a T-SQL database project that needs different schemas to be created it would be nice to place them in a T-SQL script.

While doing this you might encounter the specific error as above statement while creating a T-SQL script like:

You can try to solve this using GOTO statements but this will not work because the GO’s that are needed to keep the CREATE SCHEMA statements as is own batch:

The solution is simple, just use some “Dynamic” SQL:

Hope you enjoy this blog! When you have comments, better solution and recommendation I like to hear from you.

Dynamic Intelligence | LinkedIn | Blog | Twitter