sqlcmd
has strange behaviour on windows 10 yet works properly on Ubuntu linux box ... when the SQL file does NOT contain GO
it seems OK as per
cat some.sql
SELECT s.name AS schema_name,
s.schema_id,
u.name AS schema_owner
FROM sys.schemas s
INNER JOIN sys.sysusers u ON u.uid = s.principal_id
ORDER BY s.name;
run as
sqlcmd -S foo-bar-dev-baz-001.sql.azuresynapse.net -d My_Synapse_Dedicated_SQL_Pool -I -i some.sql
however when my SQL file contains GO
it seems to execute OK yet outputs error
There are no batches in the input script.
as per
cat select_schema_with_GO.sql
SELECT s.name AS schema_name,
s.schema_id,
u.name AS schema_owner
FROM sys.schemas s
INNER JOIN sys.sysusers u ON u.uid = s.principal_id
ORDER BY s.name;
GO
here is the run where sql file above contains GO
sqlcmd -S foo-bar-dev-baz-001.sql.azuresynapse.net -d My_Synapse_Dedicated_SQL_Pool -I -i select_schema_with_GO.sql
schema_name schema_id schema_owner
-------------------------------------------------------------------------------------------------------------------------------- ----------- --------------------------------------------------------------------------------------------------------------------------------
ADMIN 14 dbo
aaaaaaaaaaaaaaaaaaa_SELECTION_TOOL 22 dbo
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 24 dbo
cccccccccccccccccccccccccccc 42 dbo
(45 rows affected)
Msg 104309, Level 16, State 1, Server foo-bar-dev-baz-001, Line 1
There are no batches in the input script.
I am executing this on a windows 10 box using git-bash terminal connecting to a database on Azure Synapse Dedicated SQL pool
sqlcmd -?
Microsoft (R) SQL Server Command Line Tool
Version 15.0.2000.5 NT
Copyright (C) 2019 Microsoft Corporation. All rights reserved.
So should I just ignore the (error) message
There are no batches in the input script.
"There are no batches in the input script"
The above line is not an error message, but a message indicating that there are no more batches to execute. When you use the GO command in your SQL script, it divides the script into batches, and each batch is executed separately. The above message is displayed after the last batch has finished execution.
In this case, the SQL script is run successfully, and the message is just a notification that no further batches are needed to be run. Therefore, you can ignore the message and consider SQL script's execution as successful.