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.
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.


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

To know the SQL Server name and Instance name.

SELECT @@servername

To know about the databases

SELECT name from sys.databases