Running a Script in Microsoft SQL Server
You may need to run a script in a Microsoft SQL Server for example to create the tables in the Coveo Analytics database.
To run a script in Microsoft SQL Server 2008
Connect to the Microsoft SQL Server computer using an administrator account.
Start the Microsoft SQL Server Management Studio (on the Windows taskbar, select Start > All Programs > Microsoft SQL Server 2008 > SQL Server Management Studio ).
In the Connect to Server dialog box, in Server name , select the name of your SQL server instance, and then click Connect .

In Microsoft SQL Server Management Studio , on the menu, select File > Open > File .
In the Open File dialog box, browse for the script file, and then click OK .
Example: The Analytics database creation and migration scripts are available on the Coveo server in the [.Net_Front-End_Path] \Web\Analytics\Scripts\ folder.
On the SQL Editor toolbar, select the appropriate database, and then click Execute to run the script.

A message appears at the bottom of the Microsoft SQL Server Management Studio window to indicate that the execution of the script completed successfully.
SQL Server: Run A Script In Command Line Mode (SQLCMD) Inside SQL Server Management Studio (SSMS)
In mature IT shops, all deployment scripts in a release are run into the database using command-line batches as opposed to doing it by hand.
Error running SQLCMD scripts in SSMS
Occasionally, when one is testing a single script within a release to make sure it works, he/she needs to jump to the command line to test the script because commands like the following that are allowed in SQLCMD (the command-line SQL Server utility) will throw an error in SQL Server Management Studio (SSMS)
Errors in SSMS:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ‘:’.
Msg 132, Level 15, State 1, Line 3
The label ‘C’ has already been declared. Label names must be unique within a query batch or stored procedure.
Isn’t it tedious to go to the command line just to quickly test a single script (not to mention the fact that sqlcmd is very verbose)? It is just as bad if we had to comment out the offending statements. We may forget to uncomment them after testing!
SQLCMD support within SSMS version 2008+
From SSMS for 2008 and forward sqlcmd is actually baked into SSMS. You can invoke sqlcmd command-line mode while staying within the comfort of SSMS.
To do so, in SSMS
- Select the query tab that has your script
- From the main menu choose – “Query -> SQLCMD Mode”
This will run the script in the current tab in SQLCMD mode. All the command-line commands like the ones above will now be respected. Also, you are saved from the hassle of having to type-up a long command in the command-line.
For the true command-line junkie:
If you are a command-line junkie and refuse to use SSMS, here is the general syntax to run SQLCMD straightaway (simple example)
- MyServer\MyInstance is my SQL Server
- MasterScript.sql is the script to run (may reference other scripts)
- C:\_dblog\MyApp.db.log is the output file
Reference:
There are numerous options supported by SQLCMD. You can reference it here:
Как выполнить скрипт в sql server management studio
This article concerns:
- Kaspersky Security Center 13.2 (version 13.2.0.1511)
- Kaspersky Security Center 13.1 (version 13.1.0.8324)
- Kaspersky Security Center 13 (version 13.0.0.11247)
To troubleshoot your issue, a technical support engineer may ask you to run an SQL script in SQL Server Management Studio. Depending on the specified option, see the guides below for:
For running the script, use an account that has access to the Kaspersky Security Center database.
How to run a script without logging results to a file
- Download and install SQL Server Management Studio. For instructions, see the Microsoft support site.
- Run SQL Server Management Studio.
- To connect to the SQL server used by Kaspersky Security Center, click (Connect Object Explorer).

- Select the server parameters and click Connect.

- Click New Query.
- Select the Kaspersky Security Center database, its default name is KAV.
- Paste the SQL script provided by the technical support engineer into the entry field and click Execute.
The script will be executed.
How to run a script with saving results to a file
- Download and install SQL Server Management Studio. For instructions, see the Microsoft support site.
- Run SQL Server Management Studio.
- To connect to the SQL server used by Kaspersky Security Center, click (Connect Object Explorer).

- Select the server and click Connect.

- Click New Query.
- Select the Kaspersky Security Center database, its default name is KAV.
- Click (Results to file).