denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.82k stars 497 forks source link

can not Execute GO command #614

Closed majidbigdeli closed 3 years ago

majidbigdeli commented 3 years ago
query := "GO
CREATE TABLE [dbo].[user]
(
    [id] [int] NULL
)"

conn.ExecContext(context.Background(), query)

i get error "Incorrect syntax near 'GO'."

tc-hib commented 3 years ago

Hello.

This is not a valid instruction in T-SQL. This is an instruction specific to some tools, such as sqlcmd, ssms and osql. Microsoft's OLEDB driver does not make it work either. This instruction is interpreted on the client side, before anything is done with the driver. And it is never sent to the server.

See : https://docs.microsoft.com/sql/t-sql/language-elements/sql-server-utilities-statements-go

kardianos commented 3 years ago

"GO" isn't T-SQL. It is processed by the client.

You can emulate this with the "batch" package. https://pkg.go.dev/github.com/denisenkom/go-mssqldb/batch