December 21, 2011 at 8:09 am
When I try to execute the following:
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'CreditReview')
CREATE SCHEMA [CreditReview]
I get:
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'SCHEMA'.
Can anyone spot what I'm doing wrong?
The Redneck DBA
December 21, 2011 at 8:14 am
CREATE SCHEMA has to be the only statement in a batch.
To get round the limitation, use dynamic SQL.
IF NOT EXISTS (SELECT *
FROM sys.schemas
WHERE NAME = 'CreditReview')
BEGIN
DECLARE @SQL AS VARCHAR(100)
SET @SQL = 'CREATE SCHEMA [CreditReview]'
EXEC (@SQL)
END
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply