I have a Node.js app that is handling database build / versioning by reading multiple .sql
files and executing them as transactions.
The problem I am running into is that these database build scripts require a lot of GO
statements, as you cannot execute multiple CREATE
s, etc. in the same context.
However, GO
is not T-SQL and errors when used outside of a Microsoft application context.
Take the following shorthand:
CREATE database foo /* ... */
use [foo]
CREATE TABLE bar /* ... */
This would error if GO
statements were not injected between each line.
I would rather not break this into multiple .sql
files for every separate transaction - I am building a database and that would turn into hundreds of files!
I could run String.split()
functions on all go statements and have node
execute each as a separate transaction, but that seems very hacky.
Is there any standard or best-practice solution to this type of problem?
Update
Looks like a semicolon will do the trick for everything except CREATE
statements on functions
, stored procedures
, etc. Doesn't apply to tables
or databases
, though which is good.