0% found this document useful (0 votes)
25 views

How To Check The SQL Server Authentication in SQLCMD

The document discusses how to check SQL Server authentication modes and run sqlcmd commands. It provides instructions on using sqlcmd to list variables, run a T-SQL script and output the results to a file.

Uploaded by

Manu kaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

How To Check The SQL Server Authentication in SQLCMD

The document discusses how to check SQL Server authentication modes and run sqlcmd commands. It provides instructions on using sqlcmd to list variables, run a T-SQL script and output the results to a file.

Uploaded by

Manu kaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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:

You might also like