Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent of GO; #25

Open
rkosafo opened this issue Sep 24, 2017 · 2 comments
Open

Equivalent of GO; #25

rkosafo opened this issue Sep 24, 2017 · 2 comments

Comments

@rkosafo
Copy link
Contributor

rkosafo commented Sep 24, 2017

The following fails at runtime with System.Data.SqlClient.SqlException: 'Invalid column name 'code'.'

alter table Users add column code int default 0;
update Users set code = id + 1000;

This is a consistent behaviour with SSMS. This is solved using by separating the statement with GO. I do recall your explanation on how GO is used to virtually separate scripts so they are run individually. There is however no such equivalent statement. The current workaround is having the statements in different files.

Is it possible to have a statement that is equivalent to GO? Also, I'm not really sure if it is possible but if such codes can give an error at compile time, it will be very helpful since it will help with the statement that if it compiles, it works :)

@rspeele
Copy link
Collaborator

rspeele commented Sep 26, 2017

Tricky part here will be figuring out the rules T-SQL uses. Maybe it's as simple as that all queries in a single batch are run assuming the model that existed at the start of the batch (not updated in response to DDL statements run within the batch). But I feel like I've seen situations where that wasn't the case -- could be wrong. Needs experimentation.

@rkosafo
Copy link
Contributor Author

rkosafo commented Sep 26, 2017

Just found this documentation on GO. Didn't even know the query below had such an interesting result and that a ; after GO is actually a syntax error.

select 2
GO 2

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

No branches or pull requests

2 participants