fsprojects / Rezoom.SQL

Statically typechecks a common SQL dialect and translates it to various RDBMS backends
MIT License
669 stars 25 forks source link

Equivalent of GO; #25

Open rkosafo opened 7 years ago

rkosafo commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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