Why SQLCMD?

  • Days by day i am learning something new in SQL Server. Before learning anything i want to understand why do we need this feature. This is the same case when i am learning SQLCMD.

    I would like to know what are the thing that can be done through SQLCMD which are not possible through SSMS.

    Or are there any advantages that while doing a certain set of task through SQLCMD.

    Thanks in advance.

  • Are you referring to the command SQLCMD vs the Management Studio or SQLCMD mode in Management Studio?

    CEWII

  • Elliott Whitlow (6/19/2013)


    Are you referring to the command SQLCMD vs the Management Studio or SQLCMD mode in Management Studio?

    CEWII

    well since I am a newbie. it would be great to know the difference of both.

  • The command SQLCMD is a command line interface to SQL, you type in SQL commands and type GO and it does them. It also allows you to execute a set of commands in a file from the command line. There is not much of an interface and no GUI.

    The management studio provides a nice GUI to work with to do many management tasks, most of which could be accomplished using the SQLCMD command.

    The SQLCMD mode of management studio allows for some conditional logic and string replacement. I don't use it often.

    Without getting too deep there you are..

    CEWII

  • Elliott Whitlow (6/19/2013)


    The command SQLCMD is a command line interface to SQL, you type in SQL commands and type GO and it does them. It also allows you to execute a set of commands in a file from the command line. There is not much of an interface and no GUI.

    The management studio provides a nice GUI to work with to do many management tasks, most of which could be accomplished using the SQLCMD command.

    The SQLCMD mode of management studio allows for some conditional logic and string replacement. I don't use it often.

    Without getting too deep there you are..

    CEWII

    thanks for such quick reply.

    but still the same question is there anything that SQLCMD does and SSMS doesn't.

  • Because SQLCMD is a commandprompt utility it can be used to automate actions. Consider a scenario in which you need to execute 50 different scriptfiles to update an application database.

    - In SSMS you can open each scriptfile and execute it. Each time you need to open the file, press the [execute] button and close the file. This is very time consuming and boring to do.

    - With the help of some dynamic coding you can generate a batchfile with all the needed SQLCMD command lines that execute each scriptfile. To execute the complete update process of 50 files you only have to execute the single batch file.

    You'll have to generate the dynamic code to generate the batchfile, but once you have created it, it can be used time-and-time again to generate new batchfiles.

    SSMS is a good utility to do ad-hoc work and when you need an overview of settings/results.

    SQLCMD is a good utility to automate your actions.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • HanShi makes great points and is correct.

    Also I don't think the SQLCMD command line program has a SQLCMD mode like SSMS does. But that isn't used quite as much anyway so no real loss.

    SSMS has the ability to show you things in a "pretty" way and SQLCMD does not..

    CEWII

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply