August 10, 2016 at 11:56 am
RE: The following code gives the error message :
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'SCHEMA'.
-----------------------------------------------------------------
IF not exists ( Select * FROM SYS.SCHEMAS where name = 'CLAIM' )
Begin
CREATE SCHEMA CLAIM
PRINT 'Schema Created';
End
August 10, 2016 at 12:12 pm
CREATE SCHEMA must be the only statement in the batch.
Weird enough, this is considered a single statement.
CREATE SCHEMA CLAIM
CREATE TABLE Claims( ClaimId int)
CREATE TABLE OtherTable( OtherId int)
August 10, 2016 at 12:15 pm
mw112009 (8/10/2016)
RE: The following code gives the error message :Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'SCHEMA'.
-----------------------------------------------------------------
IF not exists ( Select * FROM SYS.SCHEMAS where name = 'CLAIM' )
Begin
CREATE SCHEMA CLAIM
PRINT 'Schema Created';
End
It doesn't like the IF. Try this:
IF not exists ( Select * FROM SYS.SCHEMAS where name = 'CLAIM' )
Begin
exec ('CREATE SCHEMA CLAIM');
PRINT 'Schema Created';
End
ELSE
PRINT 'Schema already Exists';
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply