Using SQLCMD utility to work with SQL Server 2012

If you are one those who likes to work with command prompt. Then this article will help you to get started.

Steps :

Method 1 :
Open the command prompt (OR) press CTRL+R and type CMD it will open the command prompt.
CTRL+R
Once you opened the command prompt type SQLCMD. If you have default instance it will open the SQLCMD utility to work with SQLServer otherwise, you will get an error.

SQLCMD
SQLCMD

Method 2 :

Now you can use

SQLCMD -S Servername\Instancename -E

In the above command -S(Capital Letter) to specify the Server name and Instance name , -E is the default option to login with the windows authentication.

Method 3:

If you want to run as the SQL Server authentication. then, you can use the below command

SQLCMD -S Servername\Instancename -U SqlUsername -P SqlPassword

Once you specified the -U, you are not supposed to use windows credentials. this option is those who want to work with SQL Server Logins

Working Examples

Use GO with after every command you type in Command Prompt.

To know the SQL Version you are running.

SELECT @@version
GO

To know the SQL Server name and Instance name.

SELECT @@servername
GO

To know about the databases

SELECT name from sys.databases
GO

Leave a Reply

Your email address will not be published. Required fields are marked *