Error: ‘CREATE VIEW’ must be the first statement in a query batch

sql

the issue: receive the following error while trying to run your .sql file:

Error: 'CREATE VIEW' must be the first statement in a query batch.
SQLState: S0001
ErrorCode: 111

your file might look like this…

drop view view1;
create view view1....

the solution: try wrapping it with “exec(”)”

drop view view1;
exec('create view view1...')

Note: if you have single quotes in your create statement escape them with a single quote, example:

exec('CREATE VIEW theView ("id") as select a.id from tableA a where a.name = ''test'' ')
Previous
Previous

no dialect mapping for jdbc type 9 – hibernate and ms sql server

Next
Next

jboss – shutdown.sh -S Exception in thread “main” java.lang.SecurityException: Failed to authenticate principal=null…