Script Without The GO Command

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I am using scptxfr.exe to script out a SQL Server 2000 database. I want to
run the script inside a VB.NET application, but the scptxfr.exe adds the
keyword GO after every command, which I believe is not a transact-sql
statement, so it errors. I did not see a command line option to turn this
off. Any other way to script a database as in an automated way and not
include the GO command?

Derek Hart
 
GO is not a TSQL statement, it is used by osql and query analyser to
determin when a batch ends so that you can have multiple batches in the
same file. Some commands require this (I believe create view must be the
only command in a batch unless you wrap it in a call to sp_executesql).

If it doesn't cause any problems you could just find replace GO with
blank.

Or you could split the file into multiple files at each GO statement and
execute each one.

Or you could copy the behaviour of osql by:
Creating a transaction
Read each line of the text file into a StringBuffer until you find a
'GO' statment
Execute the sql read on the transaction
Repeat until eof is found
Commit the transaction
 
Back
Top