Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Error: 'CREATE VIEW' must be the first statement in a query batch. #42

Open
DanielOverdevest opened this issue Sep 18, 2018 · 9 comments
Labels

Comments

@DanielOverdevest
Copy link

DanielOverdevest commented Sep 18, 2018

Type

What kind of issue is this?

[x] Bug report.
[ ] Feature request.

Current Behavior

It's not possible to deploy a view into another database, using ssc push production
Gives this error code:

Error: 'CREATE VIEW' must be the first statement in a query batch.

It looks like the current situation doesn't allow to run two statements in a single batch.

Example view:

if exists (select * from sys.objects where object_id = object_id('[sys].[database_firewall_rules]') and type = 'V')
drop view [sys].[database_firewall_rules]
go

CREATE VIEW sys.database_firewall_rules AS SELECT id, name, start_ip_address, end_ip_address, create_date, modify_date FROM sys.database_firewall_rules_table

Expected behavior

Expected to create the view for me.

Steps to Reproduce

Environment: Azure SQL Database (latest version)
ssc pull development
ssc push production

Other Information

@DanielOverdevest
Copy link
Author

@justinlettau do you think this is a bug? I still get the error using SSC PUSH production.
I think it's because it starts with 'if exists' .... then GO.. And on fifth line it have the CREATE VIEW.
Do you have already a solution for this?

@DanielOverdevest
Copy link
Author

I found out that I can change the IF exists lines and CREATE VIEW with 'CREATE OR ALTER VIEW'. This works fine for me!

@justinlettau
Copy link
Owner

@DanielOverdevest Yeah, I do think it's a bug. I believe it has to do with how the queries are executed on push. I'm glad the CREATE OR ALTER works for you. In addition to fixing this bug, i'd like to add CREATE OR ALTER as an idempotency option.

@justinlettau
Copy link
Owner

@DanielOverdevest Can you reproduce this with in the latest version? The push command is designed to separate statements by the GO and execute each segment separately; So in theory this error shouldn't occur.

@DanielOverdevest
Copy link
Author

DanielOverdevest commented Jan 18, 2019 via email

@justinlettau
Copy link
Owner

@DanielOverdevest Thanks!

@DanielOverdevest
Copy link
Author

DanielOverdevest commented Jan 25, 2019 via email

@justinlettau
Copy link
Owner

@DanielOverdevest The only issue I am aware of with Azure SQL is regarding jobs (#65). Is the error your getting look related to jobs? If so, this config should address it:

{
 "output": {
   "jobs": false
 }
}

If not, could you provide some details about the error you are seeing? Thanks.

@DanielOverdevest
Copy link
Author

DanielOverdevest commented Feb 1, 2019

I tried it out with the latest version (I had to wait until I need to push anything into production).
I still get the same error:
✖ RequestError: 'CREATE VIEW' must be the first statement in a query batch.

When I find time I'm gonna change the pull request which fixed this problem using this statement:
CREATE OR ALTER VIEW

Thanks for the 2.1.1. update by the way. Clustered Indexes of multiple columns are now better captured.

UPDATE: changing it to CREATE OR ALTER also returns the same error. So solution must be found in the way it't sent to the server and GO's, what you already suggested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants