Executing SQL Statements on the SQL Tab

When you use SQL Server Compact 3.5 (SQL Server Compact 3.5) Query Analyzer to execute SQL statements, the following conditions apply:

  • You can execute queries comprised of one SQL statement, or multiple statements separated by a semicolon (;).
  • If no text is selected when executing, SQL Server Compact 3.5 tries to execute all text on the SQL tab as a single batch.
  • Lines beginning with two dashes (--) are considered comments and are ignored.
  • You can perform text-editing tasks by using the cut, copy, and paste buttons.
  • On the SQL menu, when Word Wrap is selected, SQL statements wrap to fit on the screen of the SQL tab. When Word Wrap is not selected, SQL statements flow beyond the screen.
Icon to execute an SQL statement or a batch

Tap to execute an SQL statement or batch.

Icon to cut text

Tap to cut text.

Icon to copy text

Tap to copy text.

Icon to paste text

Tap to paste text.

Using Showplan/Execution plan

SQL Server Compact 3.5 Query Analyzer lets you generate and save Showplans or Execution Plans. You can run SQL Server Compact 3.5 Query Analyzer on the device, execute a query, and then save the XML Showplan data to a .SQLPlan file. This .SQLPlan file can then be copied to a desktop and viewed by using SQL Server Management Studio.

To generate an Execution plan

  1. On the SQL tab, select Actual Execution Plan or Estimated Execution Plan.

    Note

    Selecting Actual Execution Plan executes the query and generates the real execution plan. Selecting Estimated Execution Plan does not execute the query but generates the estimated execution plan.

  2. Type in the query and tap the execute button (the green arrow).

  3. You are prompted for a location to save the Execution Plan. Type a name to save the execution plan and tap OK. The Type field is disabled and always set to be Execution plan (*.sqlplan).

    Note

    If you selected Actual Execution Plan, SQL Server Compact 3.5 Query Analyzer will first execute the query and populate the Grid tab with the results but not yet show the Grid tab. Also , the Type field is always disabled and set to Execution plan (*.sqlplan).

  4. SQL Server Compact 3.5 Query Analyzer saves the XML data and displays the results in the Grid tab.

    Note

    If you selected Estimated Execution Plan instead of Actual Execution Plan, the Grid tab will be empty because no query was actually executed.

Managing SQL Scripts

On the SQL tab, you can create new script files for SQL Server Compact 3.5, open existing ones, and save the files to a directory. You can also save frequently used SQL statements directly in SQL Server Compact 3.5 Query Analyzer for editing and reuse. The following tasks are performed primarily by using the New, Open, and Save commands on the SQL menu.

To start a new SQL Server Compact 3.5 script file

  • On the SQL menu, tap New. This clears all text from the SQL tab to start a new script file.

To open a SQL Server Compact 3.5 script file

  • To open the most recent SQL Server Compact 3.5 script files that were previously accessed, tap the Tools menu, and then tap the file you want to open.

Or

  • On the SQL menu, tap Open. In the Name list, tap the script file you want to open. If the file you want to open does not appear in the Name list, in the Folder box, select the directory of the file; and in the Type box, specify the file type.

To save a SQL Server Compact 3.5 script file

  • To save the current script file, on the SQL menu, tap Save. If the file already exists, the most recent version that appears on the SQL tab is saved in its current directory.

Or

  • If the script file is new, in the Save As dialog box, enter the appropriate information in the Name, Folder, Type, and Location boxes.

Note

If you open a script and then make changes, the changes are automatically saved.

Saving Frequently Used SQL Statements for Editing and Reuse

You can save up to 10 frequently used SQL statements directly in SQL Server Compact 3.5 Query Analyzer, and browse the text of each statement simultaneously to determine which one you want to open for editing and reuse.

To save SQL statements

  1. On the SQL tab, select the text you want to save, and then tap the preset button (see the figure at the end of this list).
  2. In the Button Presets dialog box, tap the preset button number (1 through 10) you want the statement to correspond to. The first line of the statement appears next to the button number. If any SQL statements have been added previously, the first line of their contents appears next to their assigned button numbers. If the button number corresponds to a previously added statement, the new statement overwrites it.
  3. To save, tap OK.
Icon to save an SQL statement

Tap to save an SQL statement.

To open a saved statement

  • On the SQL tab, tap the preset button number corresponding to the saved statement. If you are not sure which button number to choose, tap the preset button to view the list of saved statements, and then tap Cancel to return to the SQL tab. The following illustration shows SQL Server Compact 3.5 Query Analyzer as it appears on a Pocket PC device.
    Query Analyzer screen shot A. Tap to open a saved SQL statement. Tap the number corresponding to the preset button number the statement was saved under.
    B. Tap to view a list of saved SQL statements and their corresponding preset button numbers, or to save an SQL statement. Text must be entered and selected to save an SQL statement.
    If you edit the SQL statement after opening it, the changes will not be reflected in the Button Presets dialog box. To save the changes, repeat the save process for saving a statement described previously.