Home > Functions and DMVs, SQL Queries, SQL Server, T-SQL, Tips & Tricks > Executing the script in batch file using “sqlcmd” command

Executing the script in batch file using “sqlcmd” command

 often create batch files to execute sql scripts ( specially SPs) and then schedule it using SQL agent job/Task Scheduler. In this post , I will show you how to create a batch file with sql commands.

First of all, The command that is used to execute SQL queries from commnd prompt is “SQLCMD“. The general syntax of this command is available in the link. I will go with a simple one as below

sqlcmd –E –S Servername –Q Query -o “Output Path”

here
-E = Trusted connection (windows authentication)
-S = Server Name
-Q = CommandLineQuery
-o = Output file path
a simple command on the commnad prompt can be written as
 
 
.
Advertisements
  1. September 15, 2013 at 4:57 pm

    Hi there! I know this is kinda off topic but I was wondering
    which blog platform are yyou using for this site? I’m
    getting tired of WordPress because I’ve had issues with hackers and I’m
    looking at options for another platform.
    I would be great if you could point me in the direction of a good platform.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: