1.
a.
b. How to check the SQL Server Authentication in sqlcmd
Before Azure, there were two options to Authenticate to SQL Server:
i. Windows Authentication where you can use an Active directory account
or a local Windows account.
ii. Windows Authentication and SQL Authentication where you can also
authenticate using an account created in SQL Server.
To detect the authentication, you can use the following sentences:
2 SELECT SERVERPROPERTY('IsIntegratedSecurityOnly')
3 GO
The result displayed is the following:
If the result is 0, it means that both authentications are enabled. If it is 1, only
Windows Authentication is enabled.
c. How to list the variables set
In order to list all the variables set, run the following command in sqlcmd:
:ListVar
It will show all the variables set:
2. Running sqlcmd in command mode
You can run sqlcmd as commands. You can run scripts in command mode.
a. How to run a T-SQL script and receive the output in a file in sqlcmd
In the next example, we will show how to run a script using sqlcmd and show the
results in another file.
We will first create a script file named columns.sql with the following sentences:
select * from adventureworks2014.information_schema.columns
In the cmd, run the following command to invoke sqlcmd:
sqlcmd -S DESKTOP-5K4TURF\SQLEXPRESS -E -i c:\sql\columns.sql -o
c:\sql\exit.txt
-i is used to specify the input. You specify the script file with the queries.
-o is used to show the results of the input in a file.
The exit.txt file will be created: