Unable to check is schema is present first I've created a SQL  script that will release a process to numerous SQL  Server instances so I want to check if a paticular schema is present before creating the schema.

I'm using the below and it creates an error but I don't understand why?

IF NOT EXISTS (SELECT 1 FROM sys.schemas s WHERE s.name = 'SQLInstance_Baseline')
    CREATE SCHEMA [SQLInstance_Baseline];


If I wrap the CREATE SCHEMA [SQLInstance_Baseline] in an EXEC i.e. EXEC('CREATE SCHEMA [SQLInstance_Baseline]') it works fine, but I don't really like doing this for best practice reasons.
The schema creation has to be the only statement within it's own batch, with no statements preceeding or following it.

As the IF statement is considered to be in the same batch, the statement is syntactically incorrect.

You have to wrap the schema creation within an EXEC, so it is considered to be in a separate batch. 

Therefore the correct syntax for what you are doing is:

IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'SQLInstance_Baseline')) 
BEGIN
    EXEC ('CREATE SCHEMA [SQLInstance_Baseline] AUTHORIZATION [dbo]')
END