Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to execute SQL statement in script and get the result output
How to execute SQL statement in script and get the result output
The tool needed here is called sqlcmd.exe, which is installed with SQL server. The location of the executable program is:

c:\ Program Files \ Microsoft SQL Server \ XXX \ Tools \ Binn

Where xxx is the version number of SQL Server you installed.

version number

SQL Server 2005 90

SQL Server 2008 100

In SQL 20 14, its location is:

c:\ Program Files \ Microsoft SQL Server \ Client SDK \ ODBC \ 1 10 \ Tools \ Binn

It seems to be installed with the client SDK.

The location of the Sqlcmd.exe has been added to the environment variable, so it can be called directly in any path. You can view the environment variables by the following command.

Settings | More

You can use sqlcmd in the following ways:

Execute sql statements directly and interactively on the command line

Script files and output files used to execute sql statements are made on the command line.

The following is a screenshot of the direct run command in sqlcmd. In addition to scripts, it can also interact with SQL Server more intuitively.