Executing Scripts and Queries on One or More Databases

Executing Scripts and Queries on a Single Database

The main editor window can be used to either execute scripts and queries on a single database, or deploy scripts and queries against all or some databases defined in a Container in parallel and get aggregated results from all those databases. In order to execute code on a single database, a new script can be started in the main editor window by selecting File → New → New Connection from the main menu, or alternatively by press the Connect icon in the toolbar . You can also open an existing SQL file by selecting File → Open → File from the main menu. When you press the Connect icon, a database connection dialog will appear and will ask you to specify the server name, credentials, and database name (see the section titled Connecting to a database to write SQL code for more information). Combine will then connect to the database you selected until the script window is closed or until you press the Disconnect icon . Note that you can also select File → New → File from the main menu. This operation will create a new editor window that will not be connected to a database. You can connect later at any time by pressing the Connect icon and provide the needed connection details.

You can tell that the editor window is connected to a database by examining the tab of the script window: If you are connected then the database icon in the tab is displayed in yellow otherwise it will be grey. The image below illustrates the main editor when one window is connected to a database and another window is not.

Figure 65:  The editor interface when one window is connected to a database and another window is not.

Once you write SQL code in the connected window, you can instruct Combine to return the estimated execution plan for your SQL statements by either pressing the CTRL+L shortcut or selecting Query → Display Estimated Execution Plan from the main menu. In addition, you can return the actual execution plan by selecting that option from the same menu, or by pressing the CTRL+M shortcut. Furthermore, you can change the connection to another database on the same server by using the database dropdown in the main toolbar. To demonstrate these features, below is an example of executing code against a single database. Notice that the actual execution plan is also returned in this example and is available next to the results grid. If any messages and SQL errors are returned from the server then these messages will be displayed in the messages window (see the messages icon on the left hand side of the results grid).

Figure 66:  Executing code against a single database and using the database dropdown to switch between server databases.

© 2001-2017 JNetDirect, Inc. All Rights Reserved.