Monthly Archives: January 2009

SQLCMD – Batch Mode

1. Executing a script file from SQLCMD. i. Create a script file by typing in the following line and save it as Message.sql print ‘Welcome today”s date is: ‘ + (convert(varchar, getdate())) ii. Now goto command prompt and type: SQLCMD … Continue reading

Posted in Uncategorized | 2 Comments

SQLCMD – Interactive Mode

First get connected into the DB Server using SQLCMD using either the windows authentication or SQL authentication as explained in the previous post. Then on the prompt you can type in the TSQL queries directly and press enter. In the … Continue reading

Posted in Uncategorized | 1 Comment

SQLCMD – Setting Up Start Up Scripts

There are instances where we might need to run some default scripts on a specified server once SQLCMD gets connected. It can be achieved in just three steps as explained below: Step 1: Create a script file which you wanted … Continue reading

Posted in Uncategorized | 1 Comment

SQLCMD – Backup and Restore database

I frequently create scripts that back up a database on one server and restore it on another server. With sqlcmd you can achieve the whole thing in a single script file because you can connect to both source and destination … Continue reading

Posted in Uncategorized | 1 Comment

SQLCMD – Using and populating variables.

This is, in my opinion, the most useful feature addition if you compare sqlcmd in SQL Server 2005 with osql in previous SQL Server versions. You can declare variables inside of sqlcmd scripts using the :setvar directive and then use … Continue reading

Posted in Uncategorized | 1 Comment

SQLCMD – Executing Scritp Files

You can execute script files in sqlcmd in two ways. If you are in DOS, you can invoke sqlcmd and use the –i option to pass in the name of the file you want to execute: sqlcmd -i”c:\sql\MySql.sql” Note: Double … Continue reading

Posted in Uncategorized | 1 Comment

Run SQLCMD from Batch files

Using SQLCMD to execute script files easily in different environments: Assume we have few script files (.sql) which needs to be run in multiple SQL Servers. Hope you would accept that’s real pain to connect into different servers from SQL … Continue reading

Posted in Uncategorized | 1 Comment

Starting using SQLCMD

When SQLCMD is run from the MS-DOS command prompt, it uses the OLE DB provider to execute the given queries. SQLCMD has batch and interactive modes. ‘Batch mode’ can be used mainly for scripting and automation tasks, while ‘Interactive mode’ … Continue reading

Posted in Uncategorized | 1 Comment

Customize SQLCMD editor

In SQLCMD, if you type ed, it will invoke a text editor and put the last command you run in the editor buffer. The default editor is Edit, a command line editor of DOS. This behavior is very similar to … Continue reading

Posted in Uncategorized | 1 Comment

What is SQLCMD utility?

Sqlcmd is one of the command line utilities included with SQL Server 2005. It was designed for executing SQL scripts and replaces the osql utility that came with previous versions of SQL Server. In addition to executing SQL code, it … Continue reading

Posted in Uncategorized | Leave a comment